LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-02-2010, 12:27 PM   #1
PeteRay
LQ Newbie
 
Registered: Jul 2009
Location: Montreal
Distribution: Linux Mint
Posts: 27

Rep: Reputation: 0
crontab shutdown not working


Hi

I'm running Ubuntu server 8.04.3 with eBox on a Dell GX280. I want to power off my box automatically every night, so as root I added a crontab entry "05 1 * * * /sbin/shutdown -P now". The command runs on schedule but most days the PC goes into a coma instead of powering off. It doesn't respond to key presses or mouse movement or Ctrl-Alt-Delete, I have to push its power button to complete the shutdown. I have tried a variety of alternatives such as "/sbin/shutdown -h" and "runlevel 0", they all behave the same way.

What am I doing wrong??
 
Old 01-02-2010, 12:36 PM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
Is the described behaviour exclusive to your cron entry?
 
Old 01-02-2010, 02:01 PM   #3
PeteRay
LQ Newbie
 
Registered: Jul 2009
Location: Montreal
Distribution: Linux Mint
Posts: 27

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by harry edwards View Post
Is the described behaviour exclusive to your cron entry?
Yes, as far as I know. The PC has always powered off as ordered from the command line.
 
Old 01-03-2010, 09:52 AM   #4
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
Do you get any error messages in either /var/log/messages, /var/log/cron or the main console window?
 
Old 01-03-2010, 06:36 PM   #5
PeteRay
LQ Newbie
 
Registered: Jul 2009
Location: Montreal
Distribution: Linux Mint
Posts: 27

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by harry edwards View Post
Do you get any error messages in either /var/log/messages, /var/log/cron or the main console window?
Not a word. There is no /var/log/cron*, but there is no error message in /var/log/* recorded at shutdown time.

I'm going to try a shell script that runs a command to rouse the hardware before shutting down:
ls -R / > /tmp/foo.lst
/sbin/shutdown -P now
In a half-dozen tests the script worked every time from the command line, and cron ran it without incident in another half dozen tests in rapid succession. On spec I also successfully tested /sbin/telinit 0 a couple of times. Later tonight cron will try it when the computer is asleep, we'll see how that works out.

Thanks for your help, Harry.
 
Old 01-04-2010, 07:48 AM   #6
PeteRay
LQ Newbie
 
Registered: Jul 2009
Location: Montreal
Distribution: Linux Mint
Posts: 27

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by PeteRay View Post
Later tonight cron will try it when the computer is asleep, we'll see how that works out.
Didn't work.
 
Old 01-04-2010, 08:07 AM   #7
voyciz
Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 425

Rep: Reputation: 40
Sounds to me like something is putting your computer into this "coma" before cron even gets to do its job.
 
Old 01-04-2010, 04:06 PM   #8
PeteRay
LQ Newbie
 
Registered: Jul 2009
Location: Montreal
Distribution: Linux Mint
Posts: 27

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by voyciz View Post
Sounds to me like something is putting your computer into this "coma" before cron even gets to do its job.
If so, it happens in the few seconds between the end of the preceding job and the launch of the shutdown job. The first of these 2 crontab commands writes the file
03 01 * * * /bin/ls -Rl / > /tmp/foo.lst
05 01 * * * /sbin/shutdown -P now
The shutdown command is executed but the system does not fully implement it.
 
Old 01-05-2010, 03:59 PM   #9
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
Another thing that it could be is the environment variables set by cron. Had a read of this page http://blog.spikesource.com/crontab.htm - try the environment command comparison part.
 
Old 01-05-2010, 08:43 PM   #10
PeteRay
LQ Newbie
 
Registered: Jul 2009
Location: Montreal
Distribution: Linux Mint
Posts: 27

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by harry edwards View Post
Another thing that it could be is the environment variables set by cron. Had a read of this page http://blog.spikesource.com/crontab.htm - try the environment command comparison part.
You're full of good pointers. I read his post, and from there read (I think) his source. /usr/lib/cron/ did not exist on my system, let alone cron.deny and cron.allow. I created (as root) the directory and populated it with an empty cron.deny, after which cron successfully powered off the PC in 2 tests. The real test will come later.
 
Old 01-06-2010, 08:08 PM   #11
PeteRay
LQ Newbie
 
Registered: Jul 2009
Location: Montreal
Distribution: Linux Mint
Posts: 27

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by PeteRay View Post
I created (as root) the directory and populated it with an empty cron.deny, after which cron successfully powered off the PC in 2 tests. The real test will come later.
Didn't work. Back to square 1.
 
Old 01-07-2010, 04:31 AM   #12
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
What about calling a script that calls the shutdown command. Although this shouldn't be necessary it will allow you to capture the output e.g.

1) Create a shell script and input the following (ensure the script is executable):

Code:
#!/bin/bash

echo "About to call shutdown" > /shutdown.log

/sbin/shutdown -h now >> /shutdown.log
2) Replace the entry in cron so that it calls your new shell script.

3) Wait for the script to be executed and check the content of the file /shutdown.log
 
Old 01-10-2010, 11:22 AM   #13
PeteRay
LQ Newbie
 
Registered: Jul 2009
Location: Montreal
Distribution: Linux Mint
Posts: 27

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by harry edwards View Post
What about calling a script that calls the shutdown command. Although this shouldn't be necessary it will allow you to capture the output
Cron has been running a script for about 10 days now:
# m h dom mon dow command
05 01 * * * /sh/poweroff

the script is as follows:
Code:
#!/bin/bash

HOME=/home/peter
LOGNAME=peter
PATH=/sh:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
SHELL=/bin/bash

export HOME LOGNAME PATH SHELL

echo $(date) Running /bin/ls -Rl >> /sh/script.log
/bin/ls -Rl / 2> /dev/null 1> /tmp/files.lst
echo $(date) Done >> /sh/script.log

echo $(date) Running /sbin/shutdown -P now >> /sh/script.log
/sbin/shutdown -P now >> /sh/script.log
echo $(date) Done >> /sh/script.log
The script records the following to /sh/script.log:
---
Wed Jan 6 01:05:51 EST 2010 Running /sbin/shutdown -P now
Wed Jan 6 01:05:51 EST 2010 Done
.
.
.
Sun Jan 10 01:05:01 EST 2010 Running /bin/ls -Rl
Sun Jan 10 01:05:53 EST 2010 Done
Sun Jan 10 01:05:53 EST 2010 Running /sbin/shutdown -P now
Sun Jan 10 01:05:53 EST 2010 Done
---

Code:
grep "Jan 10 01:0[5-9]" /var/log/*
gives the output below. I don't know if it can help.
---
auth.log:Jan 10 01:05:01 janus CRON[12364]: pam_unix(cron:session): session opened for user root by (uid=0)
auth.log:Jan 10 01:05:53 janus CRON[12364]: pam_unix(cron:session): session closed for user root
auth.log:Jan 10 01:06:01 janus sudo: ebox : TTY=console ; PWD=/ ; USER=root ; COMMAND=/var/lib/ebox/tmp/gzQ64fQF2o.cmd
auth.log:Jan 10 01:06:02 janus sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
auth.log:Jan 10 01:06:02 janus sudo: pam_unix(sudo:session): session closed for user root
auth.log:Jan 10 01:06:02 janus sudo: ebox : TTY=console ; PWD=/ ; USER=root ; COMMAND=/var/lib/ebox/tmp/Q8ppxuOCY_.cmd
auth.log:Jan 10 01:06:02 janus sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
auth.log:Jan 10 01:06:02 janus sudo: pam_unix(sudo:session): session closed for user root
[50 similar lines suppressed]
daemon.log:Jan 10 01:05:53 janus init: tty4 main process (4312) killed by TERM signal
daemon.log:Jan 10 01:05:53 janus init: tty5 main process (4313) killed by TERM signal
daemon.log:Jan 10 01:05:53 janus init: tty2 main process (4315) killed by TERM signal
daemon.log:Jan 10 01:05:53 janus init: tty3 main process (4317) killed by TERM signal
daemon.log:Jan 10 01:05:53 janus init: tty6 main process (4319) killed by TERM signal
daemon.log:Jan 10 01:05:53 janus init: tty1 main process (10022) killed by TERM signal
daemon.log:Jan 10 01:05:54 janus init: ebox.apache2-user main process ended, respawning
daemon.log:Jan 10 01:06:02 janus dhclient: There is already a pid file /var/run/dhclient.eth0.pid with pid 7023
daemon.log:Jan 10 01:06:02 janus dhclient: killed old client process, removed PID file
daemon.log:Jan 10 01:06:02 janus dhclient: Internet Systems Consortium DHCP Client V3.0.6
daemon.log:Jan 10 01:06:02 janus dhclient: Copyright 2004-2007 Internet Systems Consortium.
daemon.log:Jan 10 01:06:02 janus dhclient: All rights reserved.
daemon.log:Jan 10 01:06:02 janus dhclient: For info, please visit http://www.isc.org/sw/dhcp/
daemon.log:Jan 10 01:06:02 janus dhclient:
daemon.log:Jan 10 01:06:02 janus dhclient: Listening on LPF/eth0/00:11:43:0f:12:67
daemon.log:Jan 10 01:06:02 janus dhclient: Sending on LPF/eth0/00:11:43:0f:12:67
daemon.log:Jan 10 01:06:02 janus dhclient: Sending on Socket/fallback
daemon.log:Jan 10 01:06:02 janus dhclient: DHCPRELEASE on eth0 to 192.168.1.1 port 67
daemon.log:Jan 10 01:06:02 janus dhclient: send_packet: Network is unreachable
daemon.log:Jan 10 01:06:02 janus dhclient: send_packet: please consult README file regarding broadcast address.
daemon.log:Jan 10 01:06:08 janus init: ebox.loggerd main process (7868) killed by TERM signal
daemon.log:Jan 10 01:06:08 janus collectd[8257]: Exiting normally
daemon.log:Jan 10 01:06:14 janus collectd[8945]: Exiting normally
daemon.log:Jan 10 01:06:14 janus collectdmon[8944]: Info: collectd terminated with exit status 0
daemon.log:Jan 10 01:06:14 janus collectdmon[8944]: Info: shutting down collectdmon
debug:Jan 10 01:05:02 janus slapd[4546]: <= bdb_equality_candidates: (uidNumber) not indexed
debug:Jan 10 01:05:02 janus slapd[4546]: <= bdb_equality_candidates: (gidNumber) not indexed
debug:Jan 10 01:05:02 janus slapd[4546]: <= bdb_equality_candidates: (uidNumber) not indexed
debug:Jan 10 01:05:25 janus slapd[4546]: <= bdb_equality_candidates: (gidNumber) not indexed
debug:Jan 10 01:05:35 janus slapd[4546]: <= bdb_equality_candidates: (gidNumber) not indexed
debug:Jan 10 01:06:13 janus slapd[4546]: daemon: shutdown requested and initiated.
debug:Jan 10 01:06:13 janus slapd[4546]: slapd shutdown: waiting for 0 threads to terminate
debug:Jan 10 01:06:13 janus slapd[4546]: slapd stopped.
mail.err:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: ldap_result() failed: Can't contact LDAP server
mail.err:Jan 10 01:06:13 janus dovecot: auth(default): io_loop_handle_remove: epoll_ctl(2, 11): Bad file descriptor
mail.err:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: Can't connect to server: 127.0.0.1
mail.info:Jan 10 01:05:53 janus postgrey[4538]: 2010/01/10-01:05:53 Server closing!
mail.info:Jan 10 01:05:53 janus postgrey[4538]: Couldn't unlink "/var/run/postgrey.pid" [Permission denied]
mail.info:Jan 10 01:06:02 janus postfix/master[8150]: reload configuration /etc/postfix
mail.info:Jan 10 01:06:08 janus postfix/master[8150]: terminating on signal 15
mail.info:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: ldap_result() failed: Can't contact LDAP server
mail.info:Jan 10 01:06:13 janus dovecot: auth(default): io_loop_handle_remove: epoll_ctl(2, 11): Bad file descriptor
mail.info:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: Can't connect to server: 127.0.0.1
mail.log:Jan 10 01:05:53 janus postgrey[4538]: 2010/01/10-01:05:53 Server closing!
mail.log:Jan 10 01:05:53 janus postgrey[4538]: Couldn't unlink "/var/run/postgrey.pid" [Permission denied]
mail.log:Jan 10 01:06:02 janus postfix/master[8150]: reload configuration /etc/postfix
mail.log:Jan 10 01:06:08 janus postfix/master[8150]: terminating on signal 15
mail.log:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: ldap_result() failed: Can't contact LDAP server
mail.log:Jan 10 01:06:13 janus dovecot: auth(default): io_loop_handle_remove: epoll_ctl(2, 11): Bad file descriptor
mail.log:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: Can't connect to server: 127.0.0.1
mail.warn:Jan 10 01:05:53 janus postgrey[4538]: Couldn't unlink "/var/run/postgrey.pid" [Permission denied]
mail.warn:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: ldap_result() failed: Can't contact LDAP server
mail.warn:Jan 10 01:06:13 janus dovecot: auth(default): io_loop_handle_remove: epoll_ctl(2, 11): Bad file descriptor
mail.warn:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: Can't connect to server: 127.0.0.1
messages:Jan 10 01:05:54 janus smbd_audit: nobody|192.168.1.101|disconnect|ok|IPC$
messages:Jan 10 01:06:15 janus exiting on signal 15
syslog.0:Jan 10 01:05:01 janus /USR/SBIN/CRON[12365]: (root) CMD (/sh/poweroff)
syslog.0:Jan 10 01:05:02 janus slapd[4546]: <= bdb_equality_candidates: (uidNumber) not indexed
syslog.0:Jan 10 01:05:02 janus slapd[4546]: <= bdb_equality_candidates: (gidNumber) not indexed
syslog.0:Jan 10 01:05:02 janus slapd[4546]: <= bdb_equality_candidates: (uidNumber) not indexed
syslog.0:Jan 10 01:05:25 janus slapd[4546]: <= bdb_equality_candidates: (gidNumber) not indexed
syslog.0:Jan 10 01:05:35 janus slapd[4546]: <= bdb_equality_candidates: (gidNumber) not indexed
syslog.0:Jan 10 01:05:53 janus init: tty4 main process (4312) killed by TERM signal
syslog.0:Jan 10 01:05:53 janus init: tty5 main process (4313) killed by TERM signal
syslog.0:Jan 10 01:05:53 janus init: tty2 main process (4315) killed by TERM signal
syslog.0:Jan 10 01:05:53 janus init: tty3 main process (4317) killed by TERM signal
syslog.0:Jan 10 01:05:53 janus init: tty6 main process (4319) killed by TERM signal
syslog.0:Jan 10 01:05:53 janus init: tty1 main process (10022) killed by TERM signal
syslog.0:Jan 10 01:05:53 janus postgrey[4538]: 2010/01/10-01:05:53 Server closing!
syslog.0:Jan 10 01:05:53 janus postgrey[4538]: Couldn't unlink "/var/run/postgrey.pid" [Permission denied]
syslog.0:Jan 10 01:05:54 janus init: ebox.apache2-user main process ended, respawning
syslog.0:Jan 10 01:05:54 janus smbd_audit: nobody|192.168.1.101|disconnect|ok|IPC$
syslog.0:Jan 10 01:06:02 janus postfix/master[8150]: reload configuration /etc/postfix
syslog.0:Jan 10 01:06:02 janus dhclient: There is already a pid file /var/run/dhclient.eth0.pid with pid 7023
syslog.0:Jan 10 01:06:02 janus dhclient: killed old client process, removed PID file
syslog.0:Jan 10 01:06:02 janus dhclient: Internet Systems Consortium DHCP Client V3.0.6
syslog.0:Jan 10 01:06:02 janus dhclient: Copyright 2004-2007 Internet Systems Consortium.
syslog.0:Jan 10 01:06:02 janus dhclient: All rights reserved.
syslog.0:Jan 10 01:06:02 janus dhclient: For info, please visit http://www.isc.org/sw/dhcp/
syslog.0:Jan 10 01:06:02 janus dhclient:
syslog.0:Jan 10 01:06:02 janus dhclient: Listening on LPF/eth0/00:11:43:0f:12:67
syslog.0:Jan 10 01:06:02 janus dhclient: Sending on LPF/eth0/00:11:43:0f:12:67
syslog.0:Jan 10 01:06:02 janus dhclient: Sending on Socket/fallback
syslog.0:Jan 10 01:06:02 janus dhclient: DHCPRELEASE on eth0 to 192.168.1.1 port 67
syslog.0:Jan 10 01:06:02 janus dhclient: send_packet: Network is unreachable
syslog.0:Jan 10 01:06:02 janus dhclient: send_packet: please consult README file regarding broadcast address.
syslog.0:Jan 10 01:06:08 janus init: ebox.loggerd main process (7868) killed by TERM signal
syslog.0:Jan 10 01:06:08 janus postfix/master[8150]: terminating on signal 15
syslog.0:Jan 10 01:06:08 janus collectd[8257]: Exiting normally
syslog.0:Jan 10 01:06:13 janus slapd[4546]: daemon: shutdown requested and initiated.
syslog.0:Jan 10 01:06:13 janus slapd[4546]: slapd shutdown: waiting for 0 threads to terminate
syslog.0:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: ldap_result() failed: Can't contact LDAP server
syslog.0:Jan 10 01:06:13 janus dovecot: auth(default): io_loop_handle_remove: epoll_ctl(2, 11): Bad file descriptor
syslog.0:Jan 10 01:06:13 janus dovecot: auth(default): LDAP: Can't connect to server: 127.0.0.1
syslog.0:Jan 10 01:06:13 janus slapd[4546]: slapd stopped.
syslog.0:Jan 10 01:06:14 janus collectd[8945]: Exiting normally
syslog.0:Jan 10 01:06:14 janus collectdmon[8944]: Info: collectd terminated with exit status 0
syslog.0:Jan 10 01:06:14 janus collectdmon[8944]: Info: shutting down collectdmon
syslog.0:Jan 10 01:06:15 janus exiting on signal 15
user.log:Jan 10 01:05:54 janus smbd_audit: nobody|192.168.1.101|disconnect|ok|IPC$
---
 
Old 01-10-2010, 08:56 PM   #14
voyciz
Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 425

Rep: Reputation: 40
Does omitting that last command in the script make any difference (echoing 'Done')?
 
Old 01-12-2010, 06:38 PM   #15
PeteRay
LQ Newbie
 
Registered: Jul 2009
Location: Montreal
Distribution: Linux Mint
Posts: 27

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by voyciz View Post
Does omitting that last command in the script make any difference (echoing 'Done')?
Aside from adding one less line to script.log, it makes no difference, --
Mon Jan 11 01:05:53 EST 2010 Running /sbin/shutdown -P now
Mon Jan 11 01:05:53 EST 2010 Done
Tue Jan 12 01:05:01 EST 2010 Running /bin/ls -Rl
Tue Jan 12 01:05:36 EST 2010 Done
Tue Jan 12 01:05:36 EST 2010 Running /sbin/shutdown -P now
--
the PC still does not complete its shutdown.
Permissions? The /sh directory (where the script and the log are) has the same permissions, group and owner as most other root directories, including /boot, /dev, /bin, /etc... The script has rwxrwxr-x, the log rwxr-xr-x.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Crontab entry to shutdown if no users LostDakota Linux - Server 3 07-01-2009 09:47 AM
crontab not working mahmoud Linux - Newbie 16 07-11-2008 12:46 PM
crontab not working prashanlk Linux - General 1 05-16-2008 03:21 AM
Crontab not working Zeno McDohl Linux - Newbie 1 06-05-2007 06:52 PM
crontab not working durgap Linux - General 6 09-01-2005 02:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:57 PM.

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