开发者

UNIX script abruptly ending due to ssh command [duplicate]

开发者 https://www.devze.com 2023-04-05 20:38 出处:网络
This question already has an answer here: Closed 11 years ago. Possible Duplicate: ssh invocation in script function
This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

ssh invocation in script function

Below UNIX script abruptly ends while reading second line from file. When I comment 'ssh' command the script works as expected. I think I will have to run ssh command in a different process, but haven't got a handle yet as regards to how to do that. Any help in resolving this problem is highly appreciated.

*#!/usr/bin/ksh
exec 3<&0
exec 0<./bulkInput.dat
#cat ./bulkInput.dat | while read searchToken || (echo "reading failedi $?" &&  false)
index=0
while true
do
        index=`expr $index + 1`
        if [ $index -gt 450 ]
        then
                echo "Index limit reached. Now exiting"
                exit 0
        fi
        read searchToken
        if [ $? -ne "0" ]
        then
                echo "Read failed"
        fi
        echo "Search token is "${searchToken}
        echo "************************************ **********************************"
        echo "plsa0666 WSIP server " > WSIP.log
        ssh zq742888@plsa0666 'grep -r '$searchToken' /logs/jas/was60/wsip/wsip*/wsip*' >> WSIP.log
        echo "plsa0667 WSIP server " >> WSIP.log
        #ssh zq742888@plsa0667 'grep -r '$searchToken' /logs/jas/was60/wsip/wsip*/wsip*' >> WSIP.log
        echo "plsa0668 WSIP server " >> WSIP.log
        #ssh zq742888@plsa0668 'grep -r '$searchToken' /logs/jas/was60/wsip/wsip*/wsip*' >> WSIP.log
        echo "plsa4407 WSIP server " >> WSIP.log
        #ssh zq742888@plsa4407 'grep -r '$searchToken' /logs/jas/was60/wsip/wsip*/wsip*' >> WSIP.log
        echo "plsa0412 server " >> WSIP.log
        cp开发者_StackOverflow中文版 WSIP.log bulk/WSIP.log_${searchToken}
        echo $?
done
exec 0<&3
echo "Exiting script"*


ssh(1) is reading all of stdin and exhausting it, causing the next shell read to return false and break the loop. Try one of these:

ssh -n zq742888@plsa0666 ...

or

ssh < /dev/null zq742888@plsa0666 ...

to prevent this behavior.


Run the ssh command from the shell prompt and see what it does. If it is asking for input (e.g. password) then that may be problem.

There is also a flag to run in script mode(from memory -b but you should check) and that may also help you.

The -i flag allows you to specify the key to use if that is the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消