Scripting help

Status
Not open for further replies.

knapert

Cadet
Joined
Jan 4, 2012
Messages
5
I'm using my freenas as a backup server, with daily sftp backups running on it.
Now i want to have a sort of an surveillance script running, in case on of the backups arent running properly.

I've looked through some bash scripting, and think i am pretty close to getting what i need

This is what i have so far:

Code:
#!/bin/bash

SUBJECT="Backup is more than 48 hours old"
EMAIL="username@email.com"
MSG="/root/errormsg"

MOD=`stat -f%m $1`
NOW=`date +%s`
DIFF=$(($NOW-$MOD))
if [ $DIFF > 172800 ]; then
    echo "$1 is more than 48 hours old" > $MSG
    mail -s "$SUBJECT" "$EMAIL" < $MSG
fi


So basically, im running this as a cron job twice a day on all backups, and it's supposed to check the difference between "last modified" and "current time", and if its more than 172800 seconds/48 hours it should send an email.
I thought it was working, but then this morning it still sent me a mail, despite the backup running as it was supposed to.

I've already made sure that the script is running on the right target dir.

I think that it's the DIFF, that isn't putting out the right value, but im a newb at scripting, so im not sure.

Thanks for any replies
 

Stenull

Dabbler
Joined
Aug 22, 2011
Messages
45
Try this
Code:
#!/bin/bash

SUBJECT="Backup is more than 48 hours old"
EMAIL="username@email.com"
MSG="/root/errormsg"

MOD=`stat -f%m $1`
NOW=`date +%s`
DIFF=$(($NOW-$MOD))
if [ "$DIFF" -gt "172800" ]; then
    echo "$1 is more than 48 hours old" > $MSG
    mail -s "$SUBJECT" "$EMAIL" < $MSG
fi
 

knapert

Cadet
Joined
Jan 4, 2012
Messages
5
It worked!!

Thanks a million!

Very helpful and fast folks on these forums :)
 
Status
Not open for further replies.
Top