This is my bash script to copy a csv file to a new file that has the timestamp added to the end it is then copied to another server.
#!/bin/bash
timestamp=`date +"%Y%m%d%H%M%S"`
ssh root@172.16.1.125 mv /var/log/asterisk/cdr-csv/Master.csv /var/log/asterisk/cdr-csv/Master.csv.$timestamp
scp root@172.16.1.125:/var/log/asterisk/cdr-csv/Master.csv.$timestamp /opt/logs/asterisk/Master.csv.$timestamp
This however adds two spaces to the end of the file. Example:
Orig File: test.csv
MV File: test.csv.20160204083042(space)(space)
Then when the scp
tries to locate the file it cant file it due to the spaces at the end. I have given up as I have tried all variations.
Thanks. All it seems it was the encoding was incorrect the line endings were not set to unix. I develop on a windows machine and deploy to the server which messed up the line endings.