Geeky linux question

The Homebrew Forum

Help Support The Homebrew Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

BrewStew

Regular.
Joined
Jul 28, 2008
Messages
311
Reaction score
9
this is for you linux guys out there :ugeek:

I've written a script for our company server that cron runs daily.

this script is as follows:

Code:
#!/bin/sh

echo Subject: [BACKUP] All Company Files and Documents Backup Completeted on `date "+%d/%m/%y %l:%M %p"` > /tmp/backup-public.log
cp -vru /media/data/* /media/backup_public/ >> /tmp/backup-public.log
cat /tmp/backup-public.log | /usr/sbin/sendmail [email][email protected][/email]
rm /tmp/backup-public.log

#

a little info:

the /media/backup_public mount is a 1TB external network drive mounted by sambafs at boot up
i tried doing this via rsync but because the drive is crap, it kept getting i/o errors and halting the backup procedure.

using the cp -u switch works for us because it only bothers the server with copying new and changed files instead of the whole system, and doesn't delete files that were deleted from the originating directory... so all that's fine and working how i want it.


now for the question:

when there are no files to be copied I get a blank email from the server. so i dont know (without checking the logs) whether or not this is because it failed or because there was nothing to copy.

can someone point me in the right direction for adding something to the script that'll tell me "X files copied" or something similar using the cp script above?

cheers :cheers:
 
sure, if you copy/paste their responses :P

is that the website you PM'ed me?

cheers bud
 
Easy answer to this is that you are only asking it to log what it does but not asking it to log any errors, So when you then ask for a mail of the log if nothing has been done then you will get a blank mail.

Im a geek at heart and use linux quite a bit when I can but have to use the doz because of ease / compatability I cant program but am able to look at program code and fix it ( I have no idea why I just can ) :| :eek:

Sorry this is going to look like im teaching you to suck eggs but it makes it easy for me to understand at the same time. :wha: :wha:

But as I said looking at your code you do.
echo Subject: [BACKUP] All Company Files and Documents Backup Completeted on `date "+%d/%m/%y %l:%M %p"` > /tmp/backup-public.log
Which is mail subject and add time and date, Main field is backup-public.log...

Then cp -vru /media/data/* /media/backup_public/ >> /tmp/backup-public.log
in general copy new or changed data from A to B and make log of what was copied

When copy is finished and log is created then cat /tmp/backup-public.log | /usr/sbin/sendmail [email protected]
So it in easy speak output file to mail to be sent.

then lastly you delete the file.

With out any asking for errors to be reported you will end up with the blank mail.

You could try something like the following

Code:
LOGFILE="/tmp/backup-public.log"
DATE_STAMP=`date +"%d/%m/%Y - %HH:%MM"`
echo "${DATE_STAMP} Backup Started" >>${LOGFILE}
cp -vru /media/data/* /media/backup_public/
if [ $? != 0 ];then
# Problems with backup
DATE_STAMP_END=`date +"%d/%m/%Y - %HH:%MM"`
echo "${DATE_STAMP_END} Backup Failed" >>${LOGFILE}
#
mail -s"backup_public Failed ${DATE_STAMP_END}" [email][email protected][/email] <<EOF
EOF

else
DATE_STAMP_END=`date +"%d/%m/%Y - %HH:%MM"`
echo "${DATE_STAMP_END} Backup Finished" >> ${LOGFILE}
mail -s"backup_public Success ${DATE_STAMP_END}" [email][email protected][/email] <<EOF
EOF
fi

:whistle: yep im a geek :oops:
 
ah ha!

yes!

exactly what i needed!

thank you damfoose! i shall try that tomorrow :)

ps... i'm like you, i can read code, and understand it, but writing it from scratch leaves me something to be desired :lol:
 
Back
Top