User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

sftp_monitoring_script [2020/05/07 15:23] (current)
The SuperUser created
Line 1: Line 1:
 +Create "​myfile"​ full of random data to have an upload file
 +<​code>​head -c 10M </​dev/​urandom >​myfile</​code>​
 +Create "​serverlist"​ with servers to test, one line per server, no blank lines or comments\\
 +Create "​mail.template"​ with your body header. ​ This file is put at the top of the email if needed
 +Here is the script:
 +while read server
 +        result=`scp -B -q $FILE $server:/ >/​dev/​null 2>&​1;​ echo $?`
 +        if [ $result -eq 0 ]
 +        then
 +                echo "​`date` $server successful"​ >> $LOG
 +        else
 +                echo "​`date` $server failed"​ >> $LOG
 +                echo $server >> $T_FILE
 +        fi
 +done < /​home/​filemon/​serverlist
 +if [ `cat $T_FILE | wc -l ` -gt 0 ]
 +        cat /​home/​filemon/​mail.template $T_FILE | mailx -s "SFTP server issue" [email protected]
 +rm $T_FILE
 +Run this in cron with flock to prevent multiple instances
 +<​code>​*/​5 * * * * flock -n /​home/​filemon/​sftpmon.lck -c /​home/​filemon/​</​code>​
 +Put the log file into logrotate to keep it under control.
sftp_monitoring_script.txt ยท Last modified: 2020/05/07 15:23 by The SuperUser