1849486 Members
5928 Online
104044 Solutions
New Discussion

Re: SSH in batch.

 
hptech2
New Member

SSH in batch.

How can I run ssh in a batch file. What I am looking for is login to a remote system, move a file in the remote system's apps/logs to opt/archive/. Both apps/logs and opt/archive are in remote system. The catch here is how to skip the password prompt. A response is greatly appreciated.

Thanks,
hptech2.
6 REPLIES 6
Biswajit Tripathy
Honored Contributor

Re: SSH in batch.

In my opinion, a better solution would be to run a cron
job in the remote system itself to move the file. Any
reason why you can't do that?

- Biswajit
:-)
hptech2
New Member

Re: SSH in batch.

Thanks for the quick response. Here is the deal:
This should be done as part of an app startup in the local system. Also dont want to put a script in the remote system and execute it remotely.

Thanks,
hptech2.
Patrick Wallek
Honored Contributor

Re: SSH in batch.

If you have your SSH keys set up appropriately there should be no problem with doing passwordless login.

Say the system you want to ssh to is sysb and the one you are ssh'ing from is sysa.

Generate a public/private key pair on sysa via the ssy-keygen command. Copy the public key to sysb and put it in the .ssh/authorized_keys file in the users home directory. Be very careful of permissions. Restrict permission the the .ssh directory and its contents to 700 for the dir and 600 or 400 for the files in the dir.

Once your ssh is working from the command line using it in a script should be no problem.

Something like:

ssh sysb "mv /dir/file1 /driv/file2"

is all you need to do.
Steven E. Protter
Exalted Contributor

Re: SSH in batch.

Doc attached that might help. Pay attention to permissions.
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Michael Selvesteen_2
Trusted Contributor

Re: SSH in batch.

Alternatively you can also try SSH host based authentication. Please click the following link to learn nore about hostbased authentication

www.ssh.com/support/documentation/ online/ssh/adminguide/32/Host-Based_Authentication.html

www.csse.uwa.edu.au/~ryan/tech/ssh-no-password.html


All The best
hptech2
New Member

Re: SSH in batch.

Hi all, It worked and I am able to skip the password authentication. Thanks for the help.
-hptech2.