Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: HOW-TO: Set system time clock with rdate

  1. #11
    Join Date
    Feb 2011
    Location
    Rocky Mountains
    Posts
    14

    Default

    Part 3, Utility Files

    File: getTime
    Code:
    File: getTime.sh
    
    #!/bin/sh
    # Date: 20110627 V1.0
    # Date: 20110804 V3.1
    # Date: 20110804 V3.1b - Change loation for NO HDD - USB only
    tver="3.1b"
    # By: Mr. Gadget
    # Script: getTime [-q]
    # Option:
    #	-q quietmode, no output reported
    # Status: 0 = success, 1 = invalid input, 2 = missing Busybox, 100 = network down
    #
    # This script will set the PBO clock using the updated BusyBox (V1.18) command parser
    # with the NTPD feature. Use options for verbose on or off.
    # Get the advanced Busybox here (save with extension .asc)
    # http://busybox.net/downloads/binaries/1.16.1/busybox-mipsel
    # Tip: Make an alias in /etc/profile, 
    #      alias bb="/tmp/hdd/volumes/HDD1/bin/busybox-mipsel.asc"
    # for ongoing use of the advanced busybox commands for interactive use.
    # Be sure to modify /etc/profile with your proper TZ (timezone) too.
    # Example: TZ='MST7MDT6,J72,J310'
    
    # USER-SPECIFICS
    ### use either the global exported MGWY or this temp gateway assignment.
    # Define your Gateway-Router IP address
    tmgwy="192.168.1.253"
    
    # Use can also use prog setMGWY to define variable for your Default Gateway
    #echo "Try if global MGWY=$MGWY, else set to temp gateway"
    # Which gateway assignment, check if global variable available, else use local
    [ "$MGWY" ] || MGWY="$tmgwy"
    ### echo "MGWY is " $MGWY
    
    # Choices for file locations of your binaries:
    # Internal HDD Small partition /tmp/hdd/root (part3 = 512MB, type ext3)
    # Internal HDD Large partition /tmp/hdd/volumes/HDD1 (part1 = 500GB, type ufsd)
    # Removable USB Rear /tmp/usbmounts/sdb1 (host3 part1 = 8GB, type vfat)
    # Removable USB Front /tmp/usbmounts/sda1 (UNUSED)
    # Define where your updated BusyBox image is located (not Flash)
    # I use the bin folder on the USB (for quick removal/bypass capbility)
    #MBB="/tmp/hdd/volumes/HDD1/bin/busybox-mipsel.asc"
    #MBB="/tmp/hdd/volumes/HDD1/bin/busybox1.18.3.asc"
    MBB="/tmp/usbmounts/sdb1/bin/busybox1.18.3.asc"
    CKNET="/tmp/usbmounts/sdb1/bin/scripts/chknet"
    # END USER-SPECIFICS
    
    ### Test if input options specified
    args=`getopt qh $*`
    if test $? != 0
    then
    echo 'Version: '$tver;\
    echo 'Usage: '$0' [OPTIONS]'; echo '';\
    echo 'Options:'; echo '        -q             Quiet mode.'
    exit 1
    fi
    
    ### We may or may not have input, set the arguments
    #.#echo "Args are: " $args
    set -- $args
    
    ### Parse out the arguments, and shift as required.
    for i
    do
    case "$i" in
    -q) opt_q=$1;shift;;
    -h) echo ''; \
    echo 'getTime Version: '$tver;\
    echo 'Usage: '$0' [OPTIONS]'; echo '';\
    echo 'Options:'; echo '        -q             Quiet mode.'
    exit 1
    esac
    done
    
    ### If we did not pass any (-q) quite options, make it verbose.
    if [ -n "$opt_q" ];
    then
    ### Do something if TRUE, like save the -q input
    ###echo "Valid var opt_q=$opt_q, use it"
    ## Be real quiet
    VERBOSE=0
    ##echo "I need to be quiet"
    else
    ### Do something if FALSE
    VERBOSE=1
    ##echo "I can be verbose"
    fi
    
    # Make a redirect command for output
    redir_cmd() { 
    # Are we verbose or not (set busybox ntpd verbose -d option too)
    if [ "$VERBOSE" -eq 0 ];
    then 
    NTPV="-nq"
    "$@" > /dev/null 
    else 
    NTPV="-dnq"
    "$@" 
    fi 
    }
    
    # Start:
    # First verify the network is up before we try to get the time.
    # Validate acccess to your Router-Gateway MGWY.
    redir_cmd echo "Setting the clock from NTP"
    # Wait for the network to come up before we access the network
    # 
    $CKNET -i $MGWY -c 3 -q
    
    # Save the exit status of last command
    status=$?
    if [ $status -eq 0 ];
    then
    # Do something if network is UP
    # Network is up, how about setting the clock, 
    # oh, check to see if we have access to a good BusyBox image
    #
    if [ -s $MBB ]; then
    # File is good, Get time from NTP.ORG
    $MBB ntpd $NTPV -p pool.ntp.org
    redir_cmd date
    exit 0
    else
    # File not found - better get it right!
    redir_cmd echo "File $MBB not found"
    exit 2
    fi
    redir_cmd echo "Done"
    else
    # Do something if network is DOWN
    redir_cmd echo "Network not running. Time not set."
    exit 100
    fi 
    
    # end getTime
    If you want to see myMount.sh, let me know (it also uses chknet to see if network is up, then mount shares).

  2. #12
    Join Date
    Jan 2010
    Posts
    130

    Default

    I'll check this all out - thanks!!

  3. #13
    Join Date
    Jan 2010
    Posts
    130

    Default

    I tried the simple approach: I placed the "ntpd -nq -p pool.ntp.org" command at the very end of the rcS script, immediately preceded by "sleep 30".

    For now, that seems to be working well for my setup.

  4. #14
    Join Date
    Feb 2011
    Location
    Rocky Mountains
    Posts
    14

    Default

    Good to hear it works for you.
    Just a word of caution, if the network is not operational for any reason (using PBO in hotel, on the road...), some commands may not allow your PBO to boot completely (if you are waiting for the network). Be sure to test your commands in various situations if you plan to take it on the road.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •