在远程计算机上触发shell脚本

时间:2013-09-26 22:28:27

标签: linux shell automation

我正在尝试自动化一项工作,包括通过shell脚本执行某些步骤,将少量文件的“SCP”发送到远程计算机并在远程计算机上触发shell脚本。

有没有办法使用shell脚本或任何其他脚本来实现此任务?

提前致谢, cherryhitech

4 个答案:

答案 0 :(得分:4)

您可以使用ssh运行远程脚本,例如

$ scp some_files remote_host:some_directory/
$ ssh remote_host my_script

答案 1 :(得分:1)

您始终可以编写shell脚本。尝试查看here作为介绍。正如Paul R所说,使用scp将文件复制到该服务器或从该服务器复制文件。

如果通过“自动化”表示“计划自动运行”,请查看cron。每晚午夜运行脚本意味着运行crontab -e,然后添加以下行:

0 0 * * * /path_to_script

答案 2 :(得分:1)

如果您计划在脚本中通过SSH scp文件和/或运行命令,请确保使用公钥设置SSH身份验证。这样就不会提示您登录,而且脚本将更像“类似脚本”(非交互式)。

以下是如何执行上述操作: http://www.debian-administration.org/article/SSH_with_authentication_key_instead_of_password

完成后,您可以从脚本scp -

scp localfile remotehost:remotepath

同样,您可以在远程主机上运行 -

ssh remotehost uname -r

ssh remotehost /path/to/remote/script

答案 3 :(得分:0)

remote-script.sh上运行remote-host

ssh user@remote-host ". remote-script.sh"

具有密钥身份验证:

ssh -i local/path/to/remote/key user@remote-host ". remote-script.sh"