Add TimeStamp to cron job and write file name sent

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.

Does etc/cron.daily/TimeStamp.sh (relative path) exist or is a / missing?

1 Like

Yes the / was missing, thank you.

Any idea how to include the names of the files sent via sftp in my logfile?

Did you consider raising the log level with -v ?