定时执行任务
crontab -e
0 12 * * * cd ./path/ && bash run.sh > ./log 2>&1 &
#分 时 日 月 周 执行命令
远程执行脚本
#!/bin/bash
ssh root@***.***.***.*** << remotessh
# 远程服务器上命令
cd /user/
mkdir test
echo "Hello world !"
#执行结束
exit
#退出远程机器
remotessh
如果出现这样的提示:
Pseudo-terminal will not be allocated because stdin is not a terminal.
解决方法:
将: ssh root@... << remotessh
改为:ssh -Tq root@... << remotessh
scp 免密拷贝
- 在服务器A生成公钥私钥对
ssh-keygen
- 用ssh-copy-id将公钥复制到远程机器B中
ssh-copy-id -i .ssh/id_rsa.pub user@...
- 实现A对B的免密登陆
版权声明:本文为u013546508原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。