Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Linux 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:


    Code:
    LOG_FILE="/tmp/backup.log"
    tar cvf tar_file directory > $LOG_FILE 2>&1
    mail -s "Backup log `date`" root < $LOG_FILE
    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:
    sendmail -bi
    Or you could mail directly to the user

    Code:
    mail -s "Backup log `date`" username@host.domain < $LOG_FILE

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Location
    Baton Rouge, LA
    Posts
    37
    Thanks alot for the help. I ended up just running it like this:
    Code:
    # ./daily.dvd.backup.sh | tee output.txt | mail -s "Output from backup script" me@email.com
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...