Part 3, Utility Files
File: getTime
If you want to see myMount.sh, let me know (it also uses chknet to see if network is up, then mount shares).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


Reply With Quote