View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 4 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Fri Oct 21, 2005 4:48 pm 
Offline
Joined: Tue Mar 22, 2005 9:18 pm
Posts: 1422
Location: Brisbane, Queensland, Australia
Folks, here is a script to update the time of your system only a daily basis as well as on every boot. Once you have run this script you will need to reboot your system for the script to take effect.

Code:
#!/bin/sh
# Written by Girkers
# with help from mjl
# and tjc

#Default Variables
sys="";
quest="Do you want to enable ";
ans="? [yn]:";
choice="";

#Remove the ntpd from running
update-rc.d ntpd remove

#Set the computer to keep time via a time server
#Daily and on a boot
 echo
 sys="KnoppMyth box to update its clock via the Net";
 read -n1 -p "$quest$sys$ans" choice
 choice=$(echo $choice | tr "[a-z]" "[A-Z]")
 echo
 if [[ ${choice} = "Y" ]]; then
   region=""
   echo
   echo "Pick your time zone area via the corrosponding number:"
   echo "1 - Asia"
   echo "2 - Europe"
   echo "3 - North America"
   echo "4 - Oceania"
   echo "5 - South America"
   zone=""
   while [ -z "$zone" ] ; do
       read -n1 -p "Which region are you in:" region
       case "$region" in
         1) zone=asia ;;
         2) zone=europe ;;
         3) zone=north-america ;;
         4) zone=oceania ;;
         5) zone=south-america ;;
         *) echo "You must enter a number between 1 - 5";;
       esac
   done
   echo
   echo "Please wait; applying your settings..."

   # Set the time to update from the net
   for FILE in /etc/cron.daily/mythtv-backend /etc/init.d/bootmisc.sh ; do
      [ -f "$FILE" ] && cp "$FILE" "$FILE.old" &&
      sed -e "/ntpdate/d" <$FILE >$FILE.new
      echo "/sbin/ntpdate $zone.pool.ntp.org &" >>"$FILE.new" &&
      mv "$FILE.new" "$FILE"
   done
   echo
   echo $sys "command complete"
 else
  echo $sys "skipped"
 fi

_________________
Girkers


Last edited by Girkers on Sat Oct 22, 2005 2:44 am, edited 1 time in total.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 7:49 pm 
Offline
Joined: Fri Apr 02, 2004 10:08 am
Posts: 1637
Location: Virginia, USA
I like the script: there's some typos in the text. "KnoppMyth box to update its clock via the Net"; "corresponding number"; "Please wait: applying your settings..."


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 30, 2005 12:45 pm 
Offline
Joined: Tue Jul 12, 2005 8:01 am
Posts: 670
Location: Salem, MA
I get the following errors when I try and run your script:

Code:
root@mythtv:~# sh timeupdate.sh
: command not found 5:
: command not found 7:
: command not found 8:
: command not found 9:
: command not found 10:
: command not found 11:
update-rc.d: /etc/init.d/ntpd: file does not exist
: command not found 14:
: command not found 17: echo
: command not found 18:
Do you want to enable KnoppMyth box to update its clock via the Net? [yn]:ytimeu': not a valid identifier`choice
: command not found 21: echo
'imeupdate.sh: line 34: syntax error near unexpected token `in
'imeupdate.sh: line 34: `       case "$region" in


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 30, 2005 1:32 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
I suspect that you botched the cut and paste somehow. You shouldn't need to prefix the script name with sh since it has the appropriate #! magic on the first line. All you need to do is set the execute bit (chmod +x timeupdate.sh) and run it. That said, does bash -n timeupdate.sh show trhe same errors? I just did that on my system without any problems.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu