LinuxQuestions.org
Visit Jeremy's Blog.
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, 04: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, 05:07 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
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, 09: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, 10: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 10:13 AM.
 
Old 04-24-2008, 11: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, 01:02 PM   #6
ufmale
Member
 
Registered: Feb 2007
Posts: 385

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:20 AM
Script run by crontab won't send email Braynid Linux - Newbie 1 12-21-2007 01:16 AM
How to send an email within a script??? johnsanty Programming 19 09-02-2006 01:43 PM
script to send email message meluser Programming 2 03-26-2003 01:35 AM
cron to run a an sql query and send Email ehsan Linux - General 2 03-14-2001 11:50 PM


All times are GMT -5. The time now is 08:24 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration