Re: Scripting SSH connections
From: Greg Wooledge (wooledg_at_eeg.ccf.org)
Date: Mon, 17 May 2004 09:06:54 -0400 To: Simon Burson <Simon.Burson@telecom.co.nz>
On Mon, May 17, 2004 at 11:58:59AM +1200, Simon Burson wrote:
> I would like to write a basic shell script (Linux - bash) that will make
> an SSH connection to another machine, execute arbitrary commands, read
> back the output and log off gracefully.
Set up RSA or DSA authentication keys, and then there's no problem at
imadev:~$ cp .ssh/id_rsa.pub .ssh/authorized_keys
imadev:~$ ssh vandev ps -fu wooledg | sed 1d
wooledg 3825 3823 0 09:05:23 ? 0:00 sshd: wooledg@notty
wooledg 3826 3825 5 09:05:23 ? 0:00 ps -fu wooledg
That sort of thing. The "log off gracefully" part is a no-op. The ssh
command's output goes to stdout, so you can pipe it (as shown above),
save it in a variable, save it to a file, or whatever you need to do.