cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with SSH

Former Member
0 Kudos

Hi,

I have written a script file that first makes a ssh connection with the remote system and then does some job. My script file is as follows


#! /bin/sh
ssh 172.16.1.2 <<EOF
sa=`/usr/sbin/alternatives --config java </root/Desktop/1.txt 2>&1 | grep jdk1.6.0_05`
echo $sa
sa2=`echo $sa | sed -e 's/[^0-9]//g'`
sa3=`echo $sa2 | head -c 1 >/root/Desktop/2.txt` 
echo @sa3
echo "end"
EOF

The ssh connection is formed successfully. But sa is not printing anything. just a blank line

similarly sa3. But end is being printed. Both text files (1.txt and 2.txt)resides in the remote system. I know the problem is with this line


sa=`/usr/sbin/alternatives --config java </root/Desktop/1.txt 2>&1 | grep jdk1.6.0_05`

The command is not taking input from 1.txt which is residing on the remote system. Where am i going wrong.

Accepted Solutions (1)

Accepted Solutions (1)

former_member185954
Active Contributor
0 Kudos

Hello,

I think when you start a SSH connection to a remote server you invoke a shell in the remote server. Your currently executing shell script (which invokes the ssh connection) will run on your local machine and not the remote server.

Regards,

Siddhesh

Answers (1)

Answers (1)

former_member185954
Active Contributor
0 Kudos

you need to modify the script with something like:

ssh <remote host> <command 1>

ssh <remote host> <command 2>

ssh <remote host> <command 3>

ssh <remote host> <command 4>

ssh <remote host> <command 5>

Regards,

Siddhesh

Former Member
0 Kudos

Hi Siddesh

Ya i can execute the script file now successfully.. But still am struck at a place.


sat=`ssh 172.16.1.2 /usr/sbin/alternatives --config java </root/Desktop/1.txt 2>&1 | grep jdk1.6.0_05`

sat2=`ssh 172.16.1.2 echo $sat | sed -e 's/[^0-9]//g'`

`ssh 172.16.1.2 echo $sat2 | head -c 1 >/root/Desktop/3.txt` 

sat4=`ssh 172.16.1.2 /usr/sbin/alternatives --config java </root/Desktop/3.txt 2>&1` 

The first three lines gives me the expected results.. But the last one which takes input from 3.txt is not giving proper result... Its reading a wrong choice.... Think the problem is reading that 3.txt which has just been updated.. how can i get around this problem

former_member185954
Active Contributor
0 Kudos

Hello,

Remove the ` characters in the 3rd line.

Regards,

Siddhesh