LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2008, 03:38 PM   #1
bryanedwards05
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Rep: Reputation: 0
how to send email when script fails to run


I have a script that will backup certain aspects of my linux server to a directory then that directory is copied to a mounted windows server.

I am going to place this script to run automatically in my cron, but I wold like to know if it fails or not.

Is it possible to have in that script an if statement or something that will trigger an email saying "hey your backup didn't work" and why it didn't work?


Thanks.
Bryan
 
Old 04-17-2008, 04:07 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
How about if:

in your script there is a function which starts the backup, with a *wait* command to wait for the backup to complete; return a value (success or an error message)

then if the return value is anything other than success, mailto whomever@whereever.com subject "hey, your backup failed" body *the return from the function*
 
Old 04-22-2008, 08:18 AM   #3
bryanedwards05
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Original Poster
Rep: Reputation: 0
I am pretty new to scripts, do you have any idea how to put what you said in your post into a script, here is my backup.sh as of right now:


Code:
#!/bin/sh
# A script to backup the server to a remote share

# Change directory to where the remote share is mounted
cd /mnt/backup

# Run some compression commands
# backup configs
tar -cjpf etc.tar.bz2 /etc/
# backup homedirs
tar -cjpf home.tar.bz2 /home/
# backup web content

# Copy to mounted harddrive
cp - R /mnt/backup/* /mnt/winserv/
 
Old 04-22-2008, 09:10 AM   #4
andoni
LQ Newbie
 
Registered: Sep 2007
Posts: 8

Rep: Reputation: 0
Hi,

Quote:
Originally Posted by bryanedwards05 View Post
I am pretty new to scripts, do you have any idea how to put what you said in your post into a script, here is my backup.sh as of right now:


Code:
#!/bin/sh
# A script to backup the server to a remote share

# Change directory to where the remote share is mounted
cd /mnt/backup

# Run some compression commands
# backup configs
tar -cjpf etc.tar.bz2 /etc/
# backup homedirs
tar -cjpf home.tar.bz2 /home/
# backup web content

# Copy to mounted harddrive
cp - R /mnt/backup/* /mnt/winserv/
You should try mail "command" combined with for sentence in your bash script... man mail for more details...

If you backup OK, do not anything... if you backup fails: "mail -s "subject" < "text-file-with-hey-your-backup-failed"

Regards.

Last edited by andoni; 04-22-2008 at 09:13 AM.
 
Old 04-24-2008, 10:43 AM   #5
bryanedwards05
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Is it possible to take any errors that might result and have them placed in my log file. For example if the script runs and fails with the line "cp: target `/mnt/winserver/' is not a directory" can I have "cp: target `/mnt/winserver/' is not a directory" inputed into my backup_log?
 
Old 04-24-2008, 12:02 PM   #6
ufmale
Member
 
Registered: Feb 2007
Posts: 386

Rep: Reputation: 30
How about check if the tar.bz2 is exist ; othewise, send email
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to send email... bfloeagle Linux - General 5 10-13-2009 10:20 AM
Script run by crontab won't send email Braynid Linux - Newbie 1 12-21-2007 12:16 AM
How to send an email within a script??? johnsanty Programming 19 09-02-2006 12:43 PM
script to send email message meluser Programming 2 03-26-2003 12:35 AM
cron to run a an sql query and send Email ehsan Linux - General 2 03-14-2001 10:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration