Commit d582a380 authored by Haack's Networking's avatar Haack's Networking
Browse files

refined syntax and made it such that it adds to a permanent log, sends full...

refined syntax and made it such that it adds to a permanent log, sends full log, and removes temporary/check log at same tim
parent 75d5d1d1
......@@ -10,7 +10,7 @@
#define services and logs
rsnap="/usr/bin/rsnapshot"
logfile="/home/user/temp-alert.log"
logfile="/home/user/rsync-on-or-offiste-temp.log"
#create log file, ping server for 5 seconds, record data to log
......@@ -21,30 +21,38 @@ if
#check log for from string, which is usually sufficient evidence of a network connection, owing to the response.
grep "from" $logfile
grep "from" $logfile
wait
then
#since the ping above was a success
echo "Fred's home server seems available, $(hostname) will try running a mirror on it." >> $logfile
sudo rsync -av --log-file=/home/alert.log --delete -e 'ssh -i /home/user/.ssh/id_rsa' root@domain.com:/home/remoteusers/remotedirectory/ /media/directory/targetdirectory/
#add as many locations as you need ^^
sudo chown -R user:user /media/directory/
sudo chmod -R 770 /media/directory/
mail -s "[offsite-backup]-success-$(hostname)-$(date)" fred@hack.com < $logfile
rm $logfile
echo "Fred's home server or primary desktop seems available, $(hostname) will try running a mirror on it." >> $logfile
sudo rsync -av --log-file=/home/user/rsync-on-or-offiste-temp.log --delete -e 'ssh -i /home/user/.ssh/id_rsa' root@domain.com:/home/remoteusers/remotedirectory/ /media/directory/targetdirectory/
#add as many locations as you need ^^
wait
mail -s "[rsync-off-or-onsite]-success-$(hostname)-$(date)" fred@hack.com < $logfile
wait
cat $logfile >> /home/user/rsync-on-or-offiste.log
wait
rm $logfile
chown -R user:user /home/remoteusers/remotedirectory/
chmod -R 750 /home/remoteusers/remotedirectory/
wait
exit
else
#since the ping above was a failure
echo "Fred's home server seems unavailable, $(hostname) will try again tomorrow at this same time."
mail -s "[offsite-backup]-failure-$(hostname)-$(date)" fred@hack.com < $logfile
rm $logfile
echo "Fred's home server or primary desktop seems unavailable, $(hostname) will try again tomorrow at this same time."
mail -s "[offsite-backup]-failure-$(hostname)-$(date)" fred@hack.com < $logfile
wait
cat $logfile >> /home/user/rsync-on-or-offiste.log
wait
rm $logfile
wait
exit
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment