通过远程ssh运行完整命令 [英] Running full commands through remote ssh
问题描述
可能重复:
如何使用ssh运行shell脚本在远程计算机上?
Possible Duplicate:
how to use ssh to run shell script on a remote machine?
我正在尝试制作一个在远程服务器的日常cron作业上运行的bash脚本,以通过ssh自动登录到另一个unix框,运行一些命令,然后退出.
I am trying to make a bash script that runs on my remote server's daily cron jobs to automatically login through ssh to another unix box, run a few commands and then leave.
#!/bin/bash
ssh machinehost.com -l admin -p 2222 "/usr/bin/find /share/Public/backups/set0 -mtime +14 | xargs rm -f;
/usr/bin/find /share/Public/backups/set1 -mtime +4 | xargs rm -f;
/usr/bin/find /share/Public/backups/set2 -mtime +3 | xargs rm -f;
/usr/bin/find /share/Public/backups/set3 -mtime +21 | xargs rm -f;
/usr/bin/find /share/Public/backups/set4 -mtime +2 | xargs rm -f;
/usr/bin/find /share/Public/backups/set5 -mtime +2 | xargs rm -f;
"
我遇到的问题是,我需要修改当前的现有代码,以在执行诸如
The problem I am having is I need to modify my current existing code to do something a little more complicated before each command like
if [ $(ls /share/Public/backups/set1 -1 | wc -l ) -gt 4 ] then run above command
fi
我该如何在远程ssh机器上而不是在本地cron机器上运行此命令?
How would I go about running this command on the remote ssh machine and not on my local cron one?
推荐答案
尝试在本地编写bash脚本并调用:
Try writing your bash script locally and calling:
ssh user@example.com 'bash -s' < local_script.sh
(在讨论中找到这里)
这篇关于通过远程ssh运行完整命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!