[Techtalk] Incorporating ssh into a bash script
Hamster
hamster at hamsternet.org
Sat Jan 25 21:39:52 EST 2003
Daly,
> Now that my back-up server is working fine, my boss
> wants me to create a bash script that will ssh into
> our remote database server, create a tar ball of the
> database and copy the tar ball to the backup server.
>
> I have never written a script that initiates ssh to
> access a remote server. I was wondering if someone
> could please help me with the ssh part of the script.
> I have searched the internet for examples but have
> found none
ssh can be invoked in the following manner:
ssh -l root 192.168.100.1 tar - /some/directory >some.file
ie, you can append the command to be run on the remote machine to the end of
the ssh line.
But in order for this to work in a shell script, you will have to set it up so
that the remote machine doesnt ask you to login. This is achieved by setting up
ssh to use pass-phrase-less keys for authentication.
This means that instead of a username and password, the authentication is done
by the exchange of keys.
Once this is setup, you can have a shell script that includes something like
the following (note this isnt the only way of doing it)
ssh -l root 192.168.1.1 tar -c /some/dir > /root/name.of.tar
scp root at 192.168.1.1:/root/name.of.tar /home/root
If you need help understanding or setting up passphraseless keys, write back.
Hamster
More information about the Techtalk
mailing list