Results 1 to 3 of 3
Hello everyone,
I am working on a new backup script (have most of it already actually) but I want it to email all of the output to a set address ...
- 11-13-2008 #1Just Joined!
- Join Date
- Oct 2008
- Location
- Baton Rouge, LA
- Posts
- 37
Bash script needs to e-mail output
Hello everyone,
I am working on a new backup script (have most of it already actually) but I want it to email all of the output to a set address much like cron jobs do. How would I be able to do this? It's basically the last part I want to do for now because it will eventually be run by cron so this part won't be needed then. But I plan on running it a few times to make sure it is working properly and may not be around when it actually finishes which is why it would be nice if I could get the output emailed to root or whatever address(es) needed.
- 11-13-2008 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
You could direct the output from your backup utility to a file and then mail that file. Let's assume you're using tar to back things up. The the code would look something like:
In /etc/aliases you would have the address to mail to for root. Remember to update the sendmiail aliases database if you change this file.Code:LOG_FILE="/tmp/backup.log" tar cvf tar_file directory > $LOG_FILE 2>&1 mail -s "Backup log `date`" root < $LOG_FILE
Or you could mail directly to the userCode:sendmail -bi
Code:mail -s "Backup log `date`" username@host.domain < $LOG_FILE
- 11-15-2008 #3Just Joined!
- Join Date
- Oct 2008
- Location
- Baton Rouge, LA
- Posts
- 37
Thanks alot for the help. I ended up just running it like this:
this way I can tail the output.txt as it's running to check it out and also have all of the output e-mailed to me at the end. Again, thanks for helping me out. Gotta love the linux community.Code:# ./daily.dvd.backup.sh | tee output.txt | mail -s "Output from backup script" me@email.com


Reply With Quote