Hello,
I have written a cron job to automate the sftp of files using key authentication.
I wanted to add a timeStamp and name of file sent to a log file and append each these details to the same file each time files are sent and if possible include whether the files were sent successfully or not.
My ubuntu details:
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
Here is all the code i have so far:
cron job:
#01 17 * * * /etc/cron.daily/sftpTransfer.sh 2>&1 | etc/cron.daily/TimeStamp.sh >> /home/user/sftpLogfile.log
sftpTransfer.sh:
#!/bin/bash -x
sftp -P 2224 -oIdentityFile=~/.ssh/id_rsa/sftp -v remoteMachine@IP_address <<EOF
cd /
lcd /sftpusers/transfers/sftp/data
put *.CSV*
bye
EOF
[[ ${?} -eq 0 ]] && { echo "File transfer has been completed"; } || { echo "File transfer Failed"; }
TimeStamp.sh:
#!/bin/bash
while read x; do
echo -n `date +%d/%m/%Y\ %H:%M:%S`;
echo -n " ";
echo $x;
done
My timestamp isn't working and doesn't output anything to a logFile although it did create the file.
How can I get the timeStamp to add to the logFile and also if possible the name of the file sent with the bool of successful or not?
Many thanks.