LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-10-2004, 12:05 PM   #1
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Rep: Reputation: 30
cron job not running


Hi everyone,

I want my computer to shut itself down at 1am everyday. So what I did was type "su -c 'crontab -e'" and added in the line:

Code:
0 1 * * * init 0
Then I restarted crond by typing "/etc/init.d/crond restart". To test it, I reset my clock to 12:55am and rebooted. But when the hour rolled over, nothing happened.

I tried different things like adding quotation marks to "init 0", putting the full path ("/sbin/init 0"), and using an alternative command ("shutdown -h now"), but to no avail.

What am I doing wrong?

Thanks,

Vince
 
Old 08-10-2004, 12:45 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Try creating a log file to test:
0 1 * * * init 0 2>&1 > /tmp/shutdown.log

Do you get anything in the log when it is supposed to run?
 
Old 08-13-2004, 03:54 PM   #3
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
No, apparently it doesn't even run because when I type "cat /tmp/shutdown.log", the file hasn't even been created.
 
Old 08-13-2004, 04:17 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 11,969

Rep: Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752Reputation: 752
Have you tried
/sbin/halt
or
/sbin/poweroff
Instead of init 0
 
Old 08-14-2004, 06:29 AM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
If that doesn't work it would be interesting to see if your cron jobs are even being run - try this one for example:
0 1 * * * date 2>&1 > /tmp/cron-test.log

Do you see the correct date and time in the log file? ie - 1:30
 
Old 08-14-2004, 11:12 AM   #6
wmartino
Member
 
Registered: Sep 2003
Location: Littleton, CO
Distribution: Gentoo64 2004.3
Posts: 59

Rep: Reputation: 15
You might try creating an empty log file first. Sometomes it will not create the file for you. Try this and see if it works.

Code:
touch /tmp/cron-test.log > /dev/null
 
Old 08-23-2004, 10:32 PM   #7
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
So I added the line "29 23 * * * date 2>&1 > /tmp/shutdown.log" to my crontab file, restarted crond, and made sure that I typed "touch shutdown.log" before 23:29. But yet nothing shows up in /tmp/shutdown.log.

Any more ideas?

Thanks,
Vince

P.S. Hurray, my 400th post!

Last edited by vincebs; 08-23-2004 at 10:34 PM.
 
Old 08-24-2004, 08:24 AM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
What procedure did you use to add it to your crontab file?
 
Old 08-24-2004, 01:48 PM   #9
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
su
crontab -e
<edit>
crontab -l (to verify)
/etc/init.d/crond restart
 
Old 09-01-2004, 12:23 PM   #10
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
bump
 
Old 09-01-2004, 12:35 PM   #11
nitin_batta
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat Enterprise Server 2.1
Posts: 96

Rep: Reputation: 15
Hey just a simple test to verify whether your crond is runninig

do

<code>#su -
#touch /root/cron_test
#crontab -e

and add the following job :

0,5,10,15,20,25,30,35,40,45,50,55 * * * * date >> /root/cron_test</code>

After saving the file just verify crontab -l and also there is no need restart crond it will rebuilt its files again.

This is only a test script and will put the output of date command in /root/cron_test after 5 mins every hour.

Remember to remove it once you have tested it.



.... Nitin Batta ....
http://nitinb.blogspot.com

__________________
If this helped you, please take the time to rate the value of this post by clicking the affero button
 
Old 09-03-2004, 01:18 AM   #12
sjspig
LQ Newbie
 
Registered: Mar 2003
Distribution: Modded-Knoppix
Posts: 23

Rep: Reputation: 15
Not sure if this is it, but make sure that the init file is in the path that cron is using to run. It does not run with the full path that your user account runs as. It also runs as the user for which the cron job was created - you will likely have to be root to run this cron job as it is written.

Put the full path to init - probably /sbin/init or /usr/sbin/init - It is common that the path that cron uses is very minimal unless you specify path as a variable in cron:

PATH = /usr/sbin:/sbin:/bin:/usr/bin.....etc...
 
Old 09-06-2004, 12:49 PM   #13
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by nitin_batta
Hey just a simple test to verify whether your crond is runninig

do

<code>#su -
#touch /root/cron_test
#crontab -e

and add the following job :

0,5,10,15,20,25,30,35,40,45,50,55 * * * * date >> /root/cron_test</code>

After saving the file just verify crontab -l and also there is no need restart crond it will rebuilt its files again.

This is only a test script and will put the output of date command in /root/cron_test after 5 mins every hour.
Looks like cron works here. But I can't figure out why it won't load "init 0"

Quote:
Originally posted by sjspig
Put the full path to init - probably /sbin/init or /usr/sbin/init - It is common that the path that cron uses is very minimal unless you specify path as a variable in cron
Answer:
Quote:
Originally posted by vincebs
I tried different things like adding quotation marks to "init 0", putting the full path ("/sbin/init 0"), and using an alternative command ("shutdown -h now"), but to no avail.
So I have to be root in order for the cron job to run? I don't feel comfortable leaving my Internet-connected computer running as root all the time...

There's no other way to schedule a shutdown?
 
Old 09-06-2004, 01:07 PM   #14
nitin_batta
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat Enterprise Server 2.1
Posts: 96

Rep: Reputation: 15
Shutdown has execute permissions generally for only for the root.

Quote:
So I have to be root in order for the cron job to run? I don't feel comfortable leaving my Internet-connected computer running as root all the time...

So you will set the shutdown as a cronjob for root.

When you set a cronjob as any user you need not be logged in as that user for the job to run .... so its to set shutdown as a cronjob for root.

#which shutdown
/usr/bin/shutdown (Dummy O/p)

so u'r crontab would be

#crontab -e
0 1 * * * /usr/bin/shutdown -h now
 
Old 09-07-2004, 04:43 PM   #15
vincebs
Member
 
Registered: Oct 2003
Location: Mississauga, ON
Distribution: Ubuntu 9.04
Posts: 494

Original Poster
Rep: Reputation: 30
That's what I did originally but it didn't work.

I made sure that I su'ed before typing crontab -e. But nothing seems to happen unless I'm logged in as root.
 
  


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
Running Screen in a cron job LinuxGeek Linux - Software 1 08-03-2005 12:11 AM
script not running as a cron job sanjith11 Programming 5 11-23-2004 08:42 AM
Cron job not running in slackware9.1 marri Linux - Software 2 05-06-2004 06:54 AM
Cron job not running? james_cwy Linux - Newbie 6 12-14-2003 08:24 PM
Cron Job Not Running pzorn Linux - General 4 10-02-2003 01:38 PM


All times are GMT -5. The time now is 11:04 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration