Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Execute Remote Commands using SSH

522030Aug 30 2007 — edited Aug 31 2007
Hello 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 28 2007
Added on Aug 30 2007
4 comments
3,425 views