Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to reset the hardware clock from the system clock at shutdown. I created this script (K99savetime.sh):

#! /bin/sh
### BEGIN INIT INFO
# Provides:         savetime.sh
# Default-Start:    6 0
# Short-Description: set hwclock.
# Description:  set hwclock to systemclock on halt or reboot.
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin

log_action_msg "Updating hwclock with system clock"
hwclock --systohc
exit 0

I saved the script to /init.d, made it executable, and created a symbolic link in /etc/rc6.d

The machine appears to shutdown correctly, that is, I don't see any errors and it doesn't hang up.

  1. How do I know that the script runs at shutdown?

  2. Is the script correctly written to do what I want?

share|improve this question
    
do not know the script is written is correctly ...but some one who's posting the answer.. the might help ubuntuforums.org/showthread.php?t=185261 –  Qasim May 8 '13 at 23:55
    
The link led met to a greater understanding. Still don't know if it works! –  Nate Lockwood May 9 '13 at 23:41
    
make your script executable...then sh your-script < if it work then it will work on shutdown –  Qasim May 9 '13 at 23:49
    
To make the script run at both shutdown and restart symbolic links must be created in both /etc/rc0.d and /etc/rc6.d. The link file should be the same name as the script but with S10 prepended to the script name so that it will run early. I used "touch" to create a file just before the hwclock command and just after. It appears to work but I don't understand all the options available in the INIT secton of the script. –  Nate Lockwood May 10 '13 at 19:07
add comment

1 Answer

To make the script run at both shutdown and restart symbolic links must be created in both /etc/rc0.d and /etc/rc6.d. The link file should be the same name as the script but with S10 prepended to the script name so that it will run early. I used "touch" to create a file just before the hwclock command and just after. It appears to work but I don't understand all the options available in the INIT section of the script. –

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.