我编写了以下脚本:
#Other code above ...
read -p "Enter the full hostname for the Component we need to degrade: " input
#I move the file that I want to execute across to the specified host
rsync -azvh ~/RTL_COUNTER.sh username@$input:/home/username/
#I then want to run this process, and only have my shell script move forward when it completes (it contains a loop)
#Note that I have to sudo up here as the shell script being executed queries the JMX
ssh -t username@$input "sudo su - SUPERUSE;/home/username/RTL_COUNTER.sh"
#Other code follows ...
这是可行的,但是我需要执行而/users/username/RTL_COUNTER.sh
不是在后台运行 - 该脚本在该脚本完成之前不应继续。
有什么办法可以做到这一点吗?
注意:RTL_COUNTER.sh 如下所示:
#!/bin/bash
test="$(echo "get -s -b com.service.oms:name=XXXXXTransactionMonitor RunningTasks" | /usr/local/latest/bin/java -Xms256m -Xmx256m -jar /usr/local/bin/jmxterm-1.0-alpha-4-uber.jar --url localhost:XXXXXXXXX -urole -p ` grep controlRole PW HERE | awk '{print $2}' ` -n -v silent | wc -l)"
echo "${test}"
function check {
test="$(echo "get -s -b com.service.oms:name=XXXXXTransactionMonitor RunningTasks" | /usr/local/latest/bin/java -Xms256m -Xmx256m -jar /usr/local/bin/jmxterm-1.0-alpha-4-uber.jar --url localhost:xxxxx -u controlRole -p ` grep role XXXXXX | awk '{print $2}' ` -n -v silent | wc -l)"
if [ ${test} != "1" ]
then
echo ${test}
check
else
echo "###########################"
echo "#SAFE TO DELETE - NO TASKS#"
echo "###########################"
fi
}
check
答案1
你似乎有一个轻微的语法错误......
sudo su - SUPERUSE;/home/username/RTL_COUNTER.sh
方法...
# su to a SUPERUSE + exit, because of the ";"
# execute the script as whatever use ssh'ed into machine
/home/username/RTL_COUNTER.sh
试试这个吧...
sudo su - SUPERUSE -- /home/username/RTL_COUNTER.sh
注意删除的“;”特点。