나는 다음 스크립트를 작성했습니다.
#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
삭제된 ";" 기능을 확인하세요.