我有一个 shell 脚本来做以下事情
- sudo 作为用户 (johnsmith) 并执行一些操作
- 从该用户退出并检查 url 状态
- 如果 status 不等于 1 ,则 ssh 到另一台服务器并执行脚本。
但是当我运行它时,里面的行'ENDBASH'
根本没有被执行。
#!/bin/ksh
echo "Outside ENDBASH ${@##*/}"
sudo -u johnssmith bash <<'ENDBASH'
echo "Inside ENDBASH ${@##*/}"
#Obtaining the new version file
for file in "${@##*/}"
do
if echo "$file" | grep -E "abc_cde_efg"; then
echo "Version found: $file"
else
echo "Version not found"
fi
done
exit
ENDBASH
urlArray=('http://server:port/servicename1/services/servicename1?wsdl' 'http://server:port/servicename2/services/servicename2?wsdl')
status=0
for url in "${urlArray[@]}"
do
result=`curl -s $url`
if (echo $result | grep '<?xml' >/dev/null 2>&1); then
service=$(echo $url | cut -d"/" -f4)
echo "$service is Running"
else
service=$(echo $url | cut -d"/" -f4)
echo "$service is not Running"
status=1
fi
done
if [ $status != 1 ] ; then
ssh -t username@hostname /home/dev_was/test1.sh
fi