LinuxQuestions.org
Review your favorite Linux distribution.
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 12-03-2013, 10:42 AM   #1
aevtech
LQ Newbie
 
Registered: Nov 2013
Location: Bronx, New York
Distribution: Windows 8.1, CentOS 6.4
Posts: 4

Rep: Reputation: Disabled
Smile Cron job not working correctly.


Hello all,

I tried to run a script every night at 12:00AM via a cron job. This is how I set it up in the crontab:

Code:
(root)-(jobs:0)-(~)
(! 1002)-> crontab -l

* 0 * *	* /root/scripts/systeminfo.sh
This is the script it self:

Code:
(root)-(jobs:0)-(~)
(! 1001)-> cat /root/scripts/systeminfo.sh 
#!/bin/bash
echo
# This script will provide system information.
echo
echo "Here is the current system information for the server"
echo
echo "Clearing systeminfo.txt file..."
echo "" > systeminfo.txt
echo "Users Logged Into System" >> systeminfo.txt
echo >> systeminfo.txt
w >> systeminfo.txt
echo >> systeminfo.txt
echo "Server Uptime Information" >> systeminfo.txt
echo >> systeminfo.txt
uptime >> systeminfo.txt
echo >> systeminfo.txt
echo "Server Disk Space Information" >> systeminfo.txt
echo >> systeminfo.txt
df -h >> systeminfo.txt
echo >> systeminfo.txt
echo "Network Information" >> systeminfo.txt
echo >> systeminfo.txt
route >> systeminfo.txt
echo >> systeminfo.txt
echo "Memory Usage Information" >> systeminfo.txt
echo >> systeminfo.txt
free -g >> systeminfo.txt
echo >> systeminfo.txt
mail -s "System Status Report" manny@aevtech.com < systeminfo.txt
echo "End of Script"
It DOES run at 12:00AM BUT it runs every minute so I get a e-mail EVERY MINUTE. I thought it was only was supposed to run once at 12:00AM and that's it? Not sure what else I am missing for it to only run once every day at night.

Thank you for any and all help!
 
Old 12-03-2013, 10:45 AM   #2
gacanepa
Member
 
Registered: May 2012
Location: San Luis, Argentina
Distribution: Debian
Posts: 203

Rep: Reputation: 27
Quote:
Originally Posted by aevtech View Post
Hello all,

I tried to run a script every night at 12:00AM via a cron job. This is how I set it up in the crontab:

Code:
(root)-(jobs:0)-(~)
(! 1002)-> crontab -l

* 0 * *	* /root/scripts/systeminfo.sh
This is the script it self:

Code:
(root)-(jobs:0)-(~)
(! 1001)-> cat /root/scripts/systeminfo.sh 
#!/bin/bash
echo
# This script will provide system information.
echo
echo "Here is the current system information for the server"
echo
echo "Clearing systeminfo.txt file..."
echo "" > systeminfo.txt
echo "Users Logged Into System" >> systeminfo.txt
echo >> systeminfo.txt
w >> systeminfo.txt
echo >> systeminfo.txt
echo "Server Uptime Information" >> systeminfo.txt
echo >> systeminfo.txt
uptime >> systeminfo.txt
echo >> systeminfo.txt
echo "Server Disk Space Information" >> systeminfo.txt
echo >> systeminfo.txt
df -h >> systeminfo.txt
echo >> systeminfo.txt
echo "Network Information" >> systeminfo.txt
echo >> systeminfo.txt
route >> systeminfo.txt
echo >> systeminfo.txt
echo "Memory Usage Information" >> systeminfo.txt
echo >> systeminfo.txt
free -g >> systeminfo.txt
echo >> systeminfo.txt
mail -s "System Status Report" manny@aevtech.com < systeminfo.txt
echo "End of Script"
It DOES run at 12:00AM BUT it runs every minute so I get a e-mail EVERY MINUTE. I thought it was only was supposed to run once at 12:00AM and that's it? Not sure what else I am missing for it to only run once every day at night.

Thank you for any and all help!
Change:
Code:
* 0 * *	* /root/scripts/systeminfo.sh
with
Code:
0 0 * *	* /root/scripts/systeminfo.sh
 
Old 12-03-2013, 12:52 PM   #3
aevtech
LQ Newbie
 
Registered: Nov 2013
Location: Bronx, New York
Distribution: Windows 8.1, CentOS 6.4
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hello,

I have made the changes and will await tonight and see but I'm sure it will work. Thank you for your time and help very much!!
 
Old 12-03-2013, 12:58 PM   #4
gacanepa
Member
 
Registered: May 2012
Location: San Luis, Argentina
Distribution: Debian
Posts: 203

Rep: Reputation: 27
No problem.
But please note that you don't have to wait until tonight to see if it works . Change the time the script is supposed to run to a nearer time.
Just FYI, you first crontab entry was sending you an email every minute because that's what the * sign does.
If you type
Code:
* * * * * /path/to/your/script
Then your script will run every minute of every day of every month of every year.
On the other hand,
Code:
45 12 * * * /path/to/your/script
will run your script at exactly 12:45 every day.
You may want to take a look at this link for further details on using cron.
Have a great day!
 
  


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
MySQL backup cron job not executing correctly lakridserne Linux - Server 3 03-02-2011 09:10 AM
Standard output redirection doesn't work correctly with cron job The Pearls Master Linux - Software 1 07-22-2009 08:03 AM
cron job is not working moagalbm Linux - Newbie 7 02-29-2008 05:16 PM
Cron Job Not Working... ALInux Linux - Software 2 07-24-2007 04:15 AM
Cron job not quite working... simba_cubs Linux - General 10 11-08-2006 06:27 AM


All times are GMT -5. The time now is 03:06 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration