0
我已经做了我的剧本很容易在bash - 这脚本应该将该文件与特定的新名称从服务器1传送到远程服务器2bash脚本转移到Python - 从服务器日志复制到另一个远程服务器
灿有人帮助完成并将所有脚本传输到Python。
#!/bin/bash
path=/opt/log #Im in dir /opt/log
fdate=$(date +%Y%m%d -d "-1 day") # yesterday date
file=maillog-$fdate # log from yesterday which will be transfer to remote server
cp $path/$file /tmp/$HOSTNAME-$file # copy $file to /tmp with the specific name of $HOSTNAME + $File name
gzip /tmp/$HOSTNAME-$file # ZIP the file
[email protected] # remote server
rpath=/opt/log/maillog # remote path
scp /tmp/$HOSTNAME-$file.gz $rserver:$rpath # copy the file to remote server to remote path
rm /tmp/$HOSTNAME-$file.gz # clean the /tmp dir
#Done
这样的回答可以帮助你: http://stackoverflow.com/questions/250283/how-to-scp-in-python – jgritty 2014-09-29 17:59:54
你好这是有帮助但最后一件事我需要写而不是fdate = $(日期+%Y%m%d -d“-1天”)#昨天日期 - 这是fdate =昨天日期“格式的日期命令+%Y%m %d - 1天,怎么可能在Python中创建这个? – hansus 2014-09-30 09:36:25
试试这个答案http://stackoverflow.com/questions/441147/how-can-i-subtract-a-day-from-a-python-日期 – jgritty 2014-09-30 16:59:51