0

I have done my easy script in bash - this script should transfer the file with the specific new name from server 1 to remote server 2.

Can someone help with this and transfer all script to 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

rserver=hansus@hansus.edu.net    # 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
jgritty
  • 11,660
  • 3
  • 38
  • 60
hansus
  • 21
  • 2
  • This answer might help you: http://stackoverflow.com/questions/250283/how-to-scp-in-python – jgritty Sep 29 '14 at 17:59
  • Hello it was helpful but last thing I need to write instead of fdate=$(date +%Y%m%d -d "-1 day") # yesterday date - is this fdate = yesterday date "date command in format +%Y%m%d - 1day, how is it possible to create this one in Python? – hansus Sep 30 '14 at 09:36
  • Try this answer http://stackoverflow.com/questions/441147/how-can-i-subtract-a-day-from-a-python-date – jgritty Sep 30 '14 at 16:59

1 Answers1

0

There are several solutions to this.

One option is unison:

http://xmodulo.com/synchronize-files-between-two-servers.html

The rsync solution:

You will need to ssh into one of the servers first (this should be trivial). Once in you can run this.

rsync -rtlzv --ignore-errors -e ssh . username@hostname:/path/to/directory

from: http://darcynorman.net/2009/01/07/how-i-move-stuff-between-servers-with-rsync/

The scp solution:

I actually think this is the most elegant way because you do not have to ssh in first. Somethibng like this:

nohup scp alice@source:/the/answer/of/all bob@target.example.com:/var/tmp/42 &

from: https://unix.stackexchange.com/questions/65116/does-a-scp-transfer-close-when-i-close-the-shell

Community
  • 1
  • 1
PhysicalChemist
  • 540
  • 4
  • 14