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 09-17-2011, 09:01 AM   #1
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 52

Rep: Reputation: Disabled
Unhappy Shutdown in Crontab not executed


I'm having an issue with a scheduled shutdown command in crontab.

I recently installed my new server with mandriva 2011 and just as with my previous linux box I want it to shutdown at 2 at night.

So as with my old box I added a 'shutdown -h 1' command in crontab, but for some reason my box didn't shutdown at 2:01. (shutdown in mandriva works with minutes)

Now I allready figured out that mandriva 2011 seems to have an error/feature where you need to put a + in front of the time where that wasn't needed in 2010.
So now my crontab line says:
0 2 * * * shutdown -h +1 #shutdown at night

But for some reason it doesn't shutdown
other crontab lines seem to work just fine.

I also tried changing the crontab through webmin and automatically the shutdown doesn't happen, however if I say 'run now' from webmin the command executes just fine.

I had a look at /var/errors/cron/errors.log and I saw this error at a time where the shutdown should have run:
(CRON) EXEC FAILED (/usr/sbin/sendmail): no such file or directory

So I'm guessing there's an error somewhere which cron is trying to mail me, but I'm at a loss to what the error is, especially since the command runs fine when I start it from webmin's scheduled cron jobs module.

Hopefully somebody can give me a helping hand.

edit: forgot to mention the crontab user is root.

Last edited by RagingRaven; 09-17-2011 at 09:17 AM.
 
Old 09-17-2011, 10:19 AM   #2
sburnay
LQ Newbie
 
Registered: Sep 2011
Location: Lisbon, Portugal
Distribution: Ubuntu, CentOS & SUSE
Posts: 29

Rep: Reputation: Disabled
Hi.

This might be a bit far fetched, but I have recently had some troubles with the cron commands myself.

The problems I had were on a CentOS (which descends from the Red-Had as well as Mandriva)

How are you editing your crontab?

By the use of
Code:
root@machine ~# <some-text-editior> /etc/crontab
Or
Code:
root@machine ~# crontab -e
 
Old 09-17-2011, 10:22 AM   #3
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 52

Original Poster
Rep: Reputation: Disabled
I've used crontab -e while logged in as root user as well as through the webmin interface "scheduled cron jobs" module where i set the command to run as root.
 
Old 09-17-2011, 12:20 PM   #4
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 52

Original Poster
Rep: Reputation: Disabled
Nobody has any idea of what I could try? Or did I post this in the wrong section and it's too hard to answer ? :P
 
Old 09-17-2011, 12:33 PM   #5
sburnay
LQ Newbie
 
Registered: Sep 2011
Location: Lisbon, Portugal
Distribution: Ubuntu, CentOS & SUSE
Posts: 29

Rep: Reputation: Disabled
When you do 'crontab -e', do you find these entries in the beginning of the cron file?
Code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
 
Old 09-17-2011, 12:43 PM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Since CRON has a limited PATH, try to use
Code:
0 2 * * * /sbin/shutdown -h +1
Kind regards
 
Old 09-17-2011, 01:41 PM   #7
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 52

Original Poster
Rep: Reputation: Disabled
Thank you both for your help.

Quote:
Originally Posted by sburnay View Post
When you do 'crontab -e', do you find these entries in the beginning of the cron file?
Code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
I don't have those entries in the beginning of the crontab, should I add them?

Quote:
Originally Posted by repo View Post
Since CRON has a limited PATH, try to use
Code:
0 2 * * * /sbin/shutdown -h +1
Kind regards
I'll give it a go.
 
Old 09-17-2011, 01:49 PM   #8
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 52

Original Poster
Rep: Reputation: Disabled
adding /sbin/ appears to be working (not 100% sure yet, because I can't actually let it shutdown now, but I did get the message where before I didn't)

So am I right in thinking both your answers point to the same thing...a missing path?
In other words will it also work if I add the PATH variable to crontab and change the command back to 'shutdown -h +1' ?

In any case thanks for helping me out so far and I'll set this topic to solved as soon as my box shuts down at 2 tonight
 
Old 09-17-2011, 01:56 PM   #9
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Quote:
(CRON) EXEC FAILED (/usr/sbin/sendmail): no such file or directory
I would also suggest to fix your sendmail problem.

Kind regards
 
Old 09-17-2011, 07:19 PM   #10
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 52

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by repo View Post
I would also suggest to fix your sendmail problem.

Kind regards
Agreed, but as it is a fresh install, I haven't gotten round to it yet seeing as I'm not actually using it atm
 
Old 09-18-2011, 08:26 AM   #11
RagingRaven
Member
 
Registered: Sep 2011
Location: Oud-Beijerland, The Netherlands
Distribution: Mageia 4
Posts: 52

Original Poster
Rep: Reputation: Disabled
It worked like a charm, thanks again
 
  


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
"ps" command not executed in script when using crontab Annielover Linux - General 6 06-06-2011 03:22 PM
crontab shutdown not working PeteRay Linux - General 18 01-17-2010 10:16 AM
[SOLVED] first file which is executed when we reboot or shutdown Linux server vikas027 Linux - General 13 08-22-2009 07:14 AM
Crontab entry to shutdown if no users LostDakota Linux - Server 3 07-01-2009 10:47 AM
Specific Crontab Job is not executed . Itsik Harel Linux - Server 1 03-11-2007 10:11 PM


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