ubuntu,Debian卸载阿里云盾监控shell脚本:Syntax error: Bad for loop variable错误解决方法

卸载阿里云盾监控shell脚本

该操作适合CentOS系统。

当执行

sh uninstall.sh

或者

sh quartz_uninstall.sh

报错,Syntax error: Bad for loop variable 

查看2个sh文件都是执行到这句出现问题。

for ((var=2; var<=5; var++)) do

 

 分析:
从 ubuntu,Debian新版本, 就将先前默认的bash shell 更换成了dash shell;其表现为 /bin/sh 链接倒了/bin/dash而不是传统的/bin/bash。

    allen@allen-lql ~/workspace/script $ ls -l /bin/sh
    lrwxrwxrwx 1 root root 4 Aug 12 14:29 /bin/sh -> dash

所以在使用sh执行检测的时候实际使用的是dash,而dash不支持这种C语言格式的for循环写法。

解决办法:
1、将默认shell更改为bash。(bash支持C语言格式的for循环)

sudo dpkg-reconfigure dash

在选择项中选No

ubuntu,Debian卸载阿里云盾监控shell脚本:Syntax error: Bad for loop variable错误解决方法_第1张图片

2、直接使用bash检测:

bash uninstall.sh

bash quartz_uninstall.sh


3、为了确保shell脚本的可移植性,直接更改shell脚本,使用shell支持的for循环格式:

将这句

for ((var=2; var<=5; var++)) do

换成(do要新起一行)

for var in $(seq 2 5)

do

 

4.附内容文件uninstall.sh

systemctl status aegis

 

#!/bin/bash

#check linux Gentoo os 
var=`lsb_release -a | grep Gentoo`
if [ -z "${var}" ]; then 
	var=`cat /etc/issue | grep Gentoo`
fi

if [ -d "/etc/runlevels/default" -a -n "${var}" ]; then
	LINUX_RELEASE="GENTOO"
else
	LINUX_RELEASE="OTHER"
fi

stop_aegis(){
	killall -9 aegis_cli >/dev/null 2>&1
	killall -9 aegis_update >/dev/null 2>&1
	killall -9 AliYunDun >/dev/null 2>&1
	killall -9 AliHids >/dev/null 2>&1
	killall -9 AliHips >/dev/null 2>&1
	killall -9 AliYunDunUpdate >/dev/null 2>&1
    
    if [ -d /usr/local/aegis/aegis_debug ];then
        if [ -d /usr/local/aegis/aegis_debug/tracing/instances/aegis ];then
            echo > /usr/local/aegis/aegis_debug/tracing/instances/aegis/set_event
        else
            echo > /usr/local/aegis/aegis_debug/tracing/set_event
        fi
    fi
    
    if [ -d /sys/kernel/debug ];then
        if [ -d /sys/kernel/debug/tracing/instances/aegis ];then
            echo > /sys/kernel/debug/tracing/instances/aegis/set_event
        else
            echo > /sys/kernel/debug/tracing/set_event
        fi
    fi
    
    printf "%-40s %40s\n" "Stopping aegis" "[  OK  ]"
}

remove_aegis(){
if [ -d /usr/local/aegis ];then
    rm -rf /usr/local/aegis/aegis_client
    rm -rf /usr/local/aegis/aegis_update
	rm -rf /usr/local/aegis/alihids
fi

if [ -d /usr/local/aegis/aegis_debug ];then
    umount /usr/local/aegis/aegis_debug
    rm -rf /usr/local/aegis/aegis_debug
fi
}

uninstall_service() {
   
   if [ -f "/etc/init.d/aegis" ]; then
		/etc/init.d/aegis stop  >/dev/null 2>&1
		rm -f /etc/init.d/aegis 
   fi

	if [ $LINUX_RELEASE = "GENTOO" ]; then
		rc-update del aegis default 2>/dev/null
		if [ -f "/etc/runlevels/default/aegis" ]; then
			rm -f "/etc/runlevels/default/aegis" >/dev/null 2>&1;
		fi
    elif [ -f /etc/init.d/aegis ]; then
         /etc/init.d/aegis  uninstall
	  for var in $(seq 2 5)
          do
			if [ -d "/etc/rc${var}.d/" ];then
				 rm -f "/etc/rc${var}.d/S80aegis"
		    elif [ -d "/etc/rc.d/rc${var}.d" ];then
				rm -f "/etc/rc.d/rc${var}.d/S80aegis"
			fi
		done
    fi

}

stop_aegis
uninstall_service
remove_aegis


printf "%-40s %40s\n" "Uninstalling aegis"  "[  OK  ]"

 

你可能感兴趣的:(ubuntu,Debian卸载阿里云盾监控shell脚本:Syntax error: Bad for loop variable错误解决方法)