From f72e83b6ef7cd6846d009cd326e5668ba395e9fb Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Thu, 4 Oct 2018 10:34:58 -0400 Subject: [PATCH] Simplified check and quoted string. --- bash/feeders/adsbexchange.sh | 38 +++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/bash/feeders/adsbexchange.sh b/bash/feeders/adsbexchange.sh index f85616e..8a95ed4 100755 --- a/bash/feeders/adsbexchange.sh +++ b/bash/feeders/adsbexchange.sh @@ -119,7 +119,7 @@ echo -e "" # Check if the old style adsbexchange-maint.sh line exists in /etc/rc.local. echo -e "\e[94m Checking for any preexisting older style setups...\e[97m" -if [[ `grep -cFx "$RECEIVER_BUILD_DIRECTORY/adsbexchange/adsbexchange-maint.sh &" /etc/rc.local` -gt 0 ]] ; then +if [ ! -z $(grep "$RECEIVER_BUILD_DIRECTORY/adsbexchange/adsbexchange-maint.sh" "/etc/rc.local") ]; then # Kill any currently running instances of the adsbexchange-maint.sh script. echo -e "\e[94m Checking for any running adsbexchange-maint.sh processes...\e[97m" PIDS=`ps -efww | grep -w "$RECEIVER_BUILD_DIRECTORY/adsbexchange/adsbexchange-maint.sh &" | awk -vpid=$$ '$2 != pid { print $2 }'` @@ -132,28 +132,26 @@ if [[ `grep -cFx "$RECEIVER_BUILD_DIRECTORY/adsbexchange/adsbexchange-maint.sh & fi # Remove the old line from /etc/rc.local. echo -e "\e[94m Removing the old adsbexchange--maint.sh startup line from /etc/rc.local...\e[97m" - sudo sed -i /$RECEIVER_BUILD_DIRECTORY\/adsbexchange\/adsbexchange-maint.sh &/d /etc/rc.local 2>&1 + sudo sed -i '/$RECEIVER_BUILD_DIRECTORY\/adsbexchange\/adsbexchange-maint.sh &'/d /etc/rc.local 2>&1 fi # Remove the depreciated adsbexchange-netcat_maint.sh script. -if [ -f /etc/rc.local ]; then - echo -e "\e[94m Checking if the netcat startup line is contained within the file /etc/rc.local...\e[97m" - if ! grep -Fxq "$RECEIVER_BUILD_DIRECTORY/adsbexchange/adsbexchange-netcat_maint.sh &" /etc/rc.local; then - # Kill any currently running instances of the adsbexchange-netcat_maint.sh script. - echo -e "\e[94m Checking for any running adsbexchange-netcat_maint.sh processes...\e[97m" - if [[ $(ps -aux | grep '[a]dsbexchange-netcat_maint.sh' | awk '{print $2}') ]]; then - echo -e "\e[94m Killing the current adsbexchange-netcat_maint.sh process...\e[97m" - sudo kill -9 $(ps -aux | grep '[a]dsbexchange-netcat_maint.sh' | awk '{print $2}') &> /dev/null - fi - if [[ $(ps -aux | grep '[f]eed.adsbexchange.com' | awk '{print $2}') ]]; then - echo -e "\e[94m Killing the current feed.adsbexchange.com process...\e[97m" - sudo kill -9 $(ps -aux | grep '[f]eed.adsbexchange.com' | awk '{print $2}') &> /dev/null - fi - # Remove the depreciated netcat script start up line. - if [ -f /etc/rc.local ]; then - echo -e "\e[94m Removing the netcat startup script line to the file /etc/rc.local...\e[97m" - sudo sed -i /$RECEIVER_BUILD_DIRECTORY\/adsbexchange\/adsbexchange-netcat_maint.sh &/d /etc/rc.local 2>&1 - fi +echo -e "\e[94m Checking if the netcat startup line is contained within the file /etc/rc.local...\e[97m" +if [ ! -z $(grep "$RECEIVER_BUILD_DIRECTORY/adsbexchange/adsbexchange-netcat_maint.sh" "/etc/rc.local") ]; then + # Kill any currently running instances of the adsbexchange-netcat_maint.sh script. + echo -e "\e[94m Checking for any running adsbexchange-netcat_maint.sh processes...\e[97m" + if [[ $(ps -aux | grep '[a]dsbexchange-netcat_maint.sh' | awk '{print $2}') ]]; then + echo -e "\e[94m Killing the current adsbexchange-netcat_maint.sh process...\e[97m" + sudo kill -9 $(ps -aux | grep '[a]dsbexchange-netcat_maint.sh' | awk '{print $2}') &> /dev/null + fi + if [[ $(ps -aux | grep '[f]eed.adsbexchange.com' | awk '{print $2}') ]]; then + echo -e "\e[94m Killing the current feed.adsbexchange.com process...\e[97m" + sudo kill -9 $(ps -aux | grep '[f]eed.adsbexchange.com' | awk '{print $2}') &> /dev/null + fi + # Remove the depreciated netcat script start up line. + if [ -f /etc/rc.local ]; then + echo -e "\e[94m Removing the netcat startup script line to the file /etc/rc.local...\e[97m" + sudo sed -i '/$RECEIVER_BUILD_DIRECTORY\/adsbexchange\/adsbexchange-netcat_maint.sh &'/d /etc/rc.local 2>&1 fi fi echo -e ""