Reputation: 2200
I'm trying a automate a job, which involves, performing certain steps via shell script, do "SCP" of few files to remote machine and trigger a shell script on the remote machine.
Is there a way to achieve this task using shell script or any other scripts?
Thanks in advance, cherryhitech
Upvotes: 3
Views: 5290
Reputation: 771
run remote-script.sh
on remote-host
:
ssh user@remote-host ". remote-script.sh"
with key authentication:
ssh -i local/path/to/remote/key user@remote-host ". remote-script.sh"
Upvotes: 0
Reputation: 670
If you plan to scp files and/or run commands via SSH in a script, make sure to set up SSH authentication using public keys. That way you won't be prompted to login, and the script will be much more 'script-like' (non interactive).
Here's how to do the above: http://www.debian-administration.org/article/SSH_with_authentication_key_instead_of_password
Once done, you can scp from a script -
scp localfile remotehost:remotepath
Similarly you can run things on the remote host -
ssh remotehost uname -r
or
ssh remotehost /path/to/remote/script
Upvotes: 1
Reputation: 171
You can always write a shell script. Try looking here for an introduction. As Paul R said, use scp to copy files to or from that server.
If by "automate" you mean "schedule to run automatically", check out cron. Running the script at midnight every night would mean running crontab -e
and then adding the following line:
0 0 * * * /path_to_script
Upvotes: 1
Reputation: 212949
You can use ssh
to run a remote script, e.g.
$ scp some_files remote_host:some_directory/
$ ssh remote_host my_script
Upvotes: 5