LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-12-2009, 07:43 AM   #1
pdpd
LQ Newbie
 
Registered: Jun 2009
Posts: 1

Rep: Reputation: 0
Directory List to Email (cron) help required


Hi All,

Looking for some assistance. I'm fairly new to bash scripting, and here's the scenario.

Each week on our servers, we login to check all the backups have been taken correctly and are up to date. (We've had issues with NAS mounts and so on in the past, so need to manually check).

When we login we'll navigate to the directory containing the backups, do an 'll' command and check the dates on the files to see if they're recent (i.e. taken within the last 10 days).

We're trying to change this so that on a cron, once weekly, we are emailed a directory listing as a 'backup report' - this is easily done as follows:

ll /mnt/nas/server1 | mutt -s "NAS BACKUP REPORT - SERVER1" email@address.com

Now we want to get a bit more advanced, and make the script more generic rather than hardcoding the server name for the directory and subject.

Firstly, we'd like to print the results in date order, or even better, the script will check if there are no files backed up in the last 10 days, and then email us a 'NAS BACKUP REPORT - WARNING, OUT OF DATE BACKUPS' if it fails, and a 'SUCCESS' if the files are up to date.

Also, as we'll be running the script across various servers, we'd like to be able to send a variable from the crontab with the server name in it so we dont have to have a different .sh file for each server.

If anyone can help, that would be great!
 
Old 06-12-2009, 09:32 AM   #2
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
You might wish to look at the "find" command instead of messing around with directory listings. Furthermore, the bash variable "HOSTNAME" should contain the name of the host you're on.
 
Old 06-12-2009, 05:41 PM   #3
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
Burschik is correct, I would also suggest using 'find'. With find, you can pass the '-mtime' flag and the number of days you want to check against. In your case, it would be something like

Code:
find . -type f -mtime -10 -print
If you get a result back, then it's a success. If not, then that's a failure. That's a start for ya. Try writing the script and let us know where you're stuck at. Good luck
 
  


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
cron daemon and email fakie_flip Programming 2 11-28-2007 04:25 AM
Cron errors in cron.d directory stannerack Linux - Software 2 07-02-2007 12:57 AM
LXer: The Linux 101 Required Reading List LXer Syndicated Linux News 0 10-22-2006 04:21 PM
email server for ES3 required dave4163 Linux - Software 0 12-13-2004 07:05 PM
cron Email MaverickApollo Linux - General 6 10-26-2003 09:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:43 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