UNIX script abruptly ending due to ssh command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX script abruptly ending due to ssh command
# 1  
Old 09-20-2011
UNIX script abruptly ending due to ssh command

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.
Code:
#!/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"


Last edited by Franklin52; 09-20-2011 at 03:16 AM.. Reason: Please use code tags, thank you
# 2  
Old 09-20-2011
you need to use " (double quotes)

try this....

Code:
ssh zq742888@plsa0666 "grep -r $searchToken /logs/jas/was60/wsip/wsip*/wsip*" >> WSIP.log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh fails due to argument position.

I have a constraint to follow organization policy. So i do not have much liberty. ssh -i /opt/nonprod user1@hostone -t bash works while ssh -i /opt/nonprod -t bash user1@hostone fails How can I get this to work when I am enforced to put -t bash before the user@hostname ? Will share debug... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

SSH is failing due to unknown reason

Hi, I have setup keys between user1@server1 and user2@server2 however, the ssh is failing. server1 is Linux 3.10.0-514.6.2.el7.x86_64 #1 SMP whereas server2 is 5.10 Generic_150400-40 sun4v sparc sun4v I have checked port 22 to be open and keys to be correct. I also find the permissions... (3 Replies)
Discussion started by: mohtashims
3 Replies

3. Shell Programming and Scripting

Ssh failing due to Bad owner error

i am logged in with "user1" on host1. I m trying to ssh to host2 using user id "user2" $ ssh user2@host2 Bad owner or permissions on /home/user1/.ssh/config Question 1: Can you please tell me why am i getting the Bad owner permissions error on that directory ? Question 2: Where is it... (7 Replies)
Discussion started by: mohtashims
7 Replies

4. Shell Programming and Scripting

Exiting from the script abruptly

Hi Team, Need your help for the below code snippet. I wrote a module to read the file names remote server using file name convention. Issue : My script is coming out from while loop without reading complete file. test1() { while read line do echo $line file_nm_convention=`echo... (3 Replies)
Discussion started by: gvkumar25
3 Replies

5. UNIX for Advanced & Expert Users

OEL 6.3 :Slow login due to /etc/ssh/sshd_config configuration

Version: Oracle Enterprise Linux 6.3 Running on VMWare Workstation When I login to my Linux VM from putty, the third line prompting for password comes only after few seconds. login as: root Access denied root@192.168.0.235's password: ---> It takes around 5 seconds to get this prompt I... (1 Reply)
Discussion started by: John K
1 Replies

6. UNIX for Advanced & Expert Users

How to Switch off a Unix machine abruptly

Hi Folks, My UNIX machine is placed geographically in another location. I have a remote access towards it. I want to abruptly switch off my unix machine through remote connection. Is it possible through any UNIX commands? I practically want to power off a PC , something like unplugging a power... (12 Replies)
Discussion started by: gjasper
12 Replies

7. Shell Programming and Scripting

ssh command in unix

what does -r option mean for ssh commad. what does below commad do? ssh -r command (3 Replies)
Discussion started by: sudhakarn
3 Replies

8. Shell Programming and Scripting

how do i avoid system hang due to ssh in script?

I have a script that collects data from about 200 servers using 'ssh'. The problem is that, process sometime hangs at some point stopping the execution of the script. Please give me some idea how can I force the execution to jump to the next step if there arises any problem !! Thanks for replies if... (1 Reply)
Discussion started by: mdangol
1 Replies

9. Shell Programming and Scripting

To execute next UNIX command after ending SFTP process.

Hi, I am trying to run a simple UNIX command after i successfully executed SFTP command as shown below. ----------------------------------------- echo 'Step-1' sftp -vvv -b path exit echo 'Step-2' ------------------------------------------ In above script it executes from the 1st... (3 Replies)
Discussion started by: gautamc
3 Replies

10. Shell Programming and Scripting

ssh not ending (sometimes) from inside a script, why?

Okay I have this script file that runs from cron and most the time it works just find. Except every so often one of the three ssh commands I have in it just doesn't know it's done and that of course causes the whole thing to hang! The ssh command has executed. I can tell this because the command... (1 Reply)
Discussion started by: stilllooking
1 Replies
Login or Register to Ask a Question