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