-1

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 WSIP.log bulk/WSIP.log_${searchToken}
        echo $?
done
exec 0<&3
echo "Exiting script"*
0

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Pilcrow!! That worked! SO rocks!! And to think of it I spent 4-5 hours figuring this out!! :-)
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.