[mdlug] Execute a command on a host after ssh

Aaron Kulkis akulkis00 at gmail.com
Sat Aug 11 20:57:43 EDT 2012


R KANNAN wrote:
> Hi,
>
> I want to execute a command (more precisely change to a directory) after
> sshing into a machine. The directory location is dynamic and is to be
> passed from a script. I could not find any way of doing this from the man
> pages for 'ssh'.
>
> Any suggestions on how this can be achieved.

You are working on what we will call the local machine,
and ssh'ing to the remote machine

You keep a script on the local machine,
you scp the script to the remote machine,
say to /tmp on the remote machjine,
execute it via ssh, and then remove it.

	$ su
	password:
	# scp scriptname remote:/tmp/scriptname
	# ssh remote /tmp/scriptname
	# ssh remote rm /tmp/scriptname
	# exit
	$






More information about the mdlug mailing list