Execute Remote Commands using SSH
522030Aug 30 2007 — edited Aug 31 2007Hello All,
I am new to Unix shell scripting. I've a requirement to execute a perl script that is residing in a Unix server from another server. I am using SSH in my shell script to connect to the machine containing the perl script. Could someone please let me know :
1. How to SSH to a particular directory on the target machine. (since when I ssh, it goes to the home directory, and my perl script is in some other directory).
2. Once I ssh to the target machine, can I execute some commands in shell script? If so, where will these be executed, source or target server?
My sample code is :
cmd="ssh usr@target"
x="$($cmd cd test_dir)" /*** change to the directory containing the perl script ***/
y="$($cmd pwd)"/*** but this is giving me the source path from where the shell script is executed ****/
echo $y
Is there any way I can change to a directory after ssh'ing to the target server?
Thanks in advance.