Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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*
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/
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"
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.