adb shell setprop persist.sys.timezone "America/Chicago"
from datetime import datetime
date_object = datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p')
Link to the Python documentation for strptime
and a link for the strftime format mask
8.1.7. strftime() and strptime() Behavior
date, datetime, and time objects all support a strftime(format) method, to create a string representing the time under the control of an explicit format string. Broadly speaking, d.strftime(fmt) acts like the time module’s time.strftime(fmt, d.timetuple()) although not all objects support a timetuple() method.
Conversely, the datetime.strptime() class method creates a datetime object from a string representing a date and time and a corresponding format string. datetime.strptime(date_string, format) is equivalent to datetime(*(time.strptime(date_string, format)[0:6])).
For time objects, the format codes for year, month, and day should not be used, as time objects have no such values. If they’re used anyway, 1900 is substituted for the year, and 1 for the month and day.
For date objects, the format codes for hours, minutes, seconds, and microseconds should not be used, as date objects have no such values. If they’re used anyway, 0 is substituted for them.
The full set of format codes supported varies across platforms, because Python calls the platform C library’s strftime() function, and platform variations are common. To see the full set of format codes supported on your platform, consult the strftime(3)documentation.
The following is a list of all the format codes that the C standard (1989 version) requires, and these work on all platforms with a standard C implementation. Note that the 1999 version of the C standard added additional format codes.
The exact range of years for which strftime() works also varies across platforms. Regardless of platform, years before 1900 cannot be used.
Directive | Meaning | Example | Notes |
---|
%a | Weekday as locale’s abbreviated name. | Sun, Mon, ..., Sat (en_US); So, Mo, ..., Sa (de_DE) | (1) |
%A | Weekday as locale’s full name. | Sunday, Monday, ..., Saturday (en_US); Sonntag, Montag, ..., Samstag (de_DE) | (1) |
%w | Weekday as a decimal number, where 0 is Sunday and 6 is Saturday. | 0, 1, ..., 6 | |
%d | Day of the month as a zero-padded decimal number. | 01, 02, ..., 31 | |
%b | Month as locale’s abbreviated name. | Jan, Feb, ..., Dec (en_US); Jan, Feb, ..., Dez (de_DE) | (1) |
%B | Month as locale’s full name. | January, February, ..., December (en_US); Januar, Februar, ..., Dezember (de_DE) | (1) |
%m | Month as a zero-padded decimal number. | 01, 02, ..., 12 | |
%y | Year without century as a zero-padded decimal number. | 00, 01, ..., 99 | |
%Y | Year with century as a decimal number. | 1970, 1988, 2001, 2013 | |
%H | Hour (24-hour clock) as a zero-padded decimal number. | 00, 01, ..., 23 | |
%I | Hour (12-hour clock) as a zero-padded decimal number. | 01, 02, ..., 12 | |
%p | Locale’s equivalent of either AM or PM. | AM, PM (en_US); am, pm (de_DE) | (1), (2) |
%M | Minute as a zero-padded decimal number. | 00, 01, ..., 59 | |
%S | Second as a zero-padded decimal number. | 00, 01, ..., 59 | (3) |
%f | Microsecond as a decimal number, zero-padded on the left. | 000000, 000001, ..., 999999 | (4) |
%z | UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive). | (empty), +0000, -0400, +1030 | (5) |
%Z | Time zone name (empty string if the object is naive). | (empty), UTC, EST, CST | |
%j | Day of the year as a zero-padded decimal number. | 001, 002, ..., 366 | |
%U | Week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0. | 00, 01, ..., 53 | (6) |
%W | Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0. | 00, 01, ..., 53 | (6) |
%c | Locale’s appropriate date and time representation. | Tue Aug 16 21:30:00 1988 (en_US); Di 16 Aug 21:30:00 1988 (de_DE) | (1) |
%x | Locale’s appropriate date representation. | 08/16/88 (None); 08/16/1988 (en_US); 16.08.1988 (de_DE) | (1) |
%X | Locale’s appropriate time representation. | 21:30:00 (en_US); 21:30:00 (de_DE) | (1) |
%% | A literal '%' character. | % | |
Notes:
Because the format depends on the current locale, care should be taken when making assumptions about the output value. Field orderings will vary (for example, “month/day/year” versus “day/month/year”), and the output may contain Unicode characters encoded using the locale’s default encoding (for example, if the current locale is ja_JP, the default encoding could be any one of eucJP, SJIS, or utf-8; use locale.getlocale() to determine the current locale’s encoding).
When used with the strptime() method, the %p directive only affects the output hour field if the %I directive is used to parse the hour.
Unlike the time module, the datetime module does not support leap seconds.
%f is an extension to the set of format characters in the C standard (but implemented separately in datetime objects, and therefore always available). When used with the strptime() method, the %f directive accepts from one to six digits and zero pads on the right.
New in version 2.6.
For a naive object, the %z and %Z format codes are replaced by empty strings.
For an aware object:
- %z
utcoffset() is transformed into a 5-character string of the form +HHMM or -HHMM, where HH is a 2-digit string giving the number of UTC offset hours, and MM is a 2-digit string giving the number of UTC offset minutes. For example, ifutcoffset() returns timedelta(hours=-3, minutes=-30), %z is replaced with the string '-0330'.
- %Z
If tzname() returns None, %Z is replaced by an empty string. Otherwise %Z is replaced by the returned value, which must be a string.
When used with the strptime() method, %U and %W are only used in calculations when the day of the week and the year are specified.
Footnotes
View Full Version : HOW-TO: Set system time clock with rdate
Mr. Gadget
02-08-2011, 08:29 PM
Set your system time with RDATE or NTPD
You can set your PBO system time clock to the current time using the command 'rdate'. You will need to download and add the latest Busybox commands (do not overlay on existing commands, unless you know what you are doing).
1) Perform the addition of the latest Busybox commands to your system. You can run them from your HD or USB, not sure about using internal memory. The Busybox file is only 1.6Mb, but I would not want to deny the OS from using available space. If you want to test this feature before making it permanent, insert a USB drive on the PBO, browse to the USB drive from your PC, map it to a drive letter like V:, then download busybox-mipsel.asc file to the mapped/USB drive (save target, and add the file extension .asc).
Snappy has this file information listed here: http://www.patriotmem.com/forums/showthread.php?t=3737
A quick test to see if the new BBox commands work (I placed my file in the root of the front USB, which is /tmp/usbmounts/sda1).
Create an alias to your new commands on Venus:
Venus> alias bb="/tmp/usbmounts/sda1/busybox-mipsel.asc"
Test it with 'whoami', it should return root, if you get "-sh: whoami: not found" you are not linked to the proper file.
Venus> bb whoami
root
2) Next you should modify your /etc/profile to match your proper TZ (timezone). Example: TZ=MST7MDT
This will allow you to see your time in your local format (assuming the timezone file is current for your location, too detailed for this mod).
You can display the 'current' set date/time for your timezone, but if you did not set the date manually already, it will be wrong. Just enter the command 'date'. Don't worry about any of the fields other than your timezone, ie MST, PST...
3) Now your system is armed to get access and display the proper time. So, first we will update the System clock from the network. We need to use an older time server since most do not accept the rdate protocol command. If we can get NTP loaded on the PBO, then we can use any Stratum NTP server available (pool.ntp.org).
Enter the command:
Venus> bb rdate -sp time-nw.nist.gov
Tue Feb 8 12:53:33 2011
So now your system has the correct time. But the hardware clock is still out of sync with the system time. We can view this using the 'hwclock' command.
Venus> hwclock
Thu Dec 31 17:12:33 2009 0000000000.000000 seconds
Let's fix the hardware clock and sync it with the system clock.
Venus> hwclock -w
Now verify the System clock and Hardware clock are in sync. Just enter the 'date' command, then compare with the 'hwclock' command results.
Your system is now set to the current time, and your display should be set to your local timezone.
Update: Use NTP to set clock. Can ignore hwclock settings at this point in time, the RTC does not advance after setting anyway.
(Verbose mode)
Venus> bb ntpd -dnq -p pool.ntp.org
(Quiet mode)
Venus> bb ntpd -nq -p pool.ntp.org
TODO:
Decide which clock is more important: System (telnet) time, or PBO (GUI) time.
(GUI Time displays UTC time, telnet system clock shows TZ time).
Make it permanent (every system boot).
DONE:
Install NTP for greater accuracy and more system support. Part of the new busybox command set.
WOW -- The hwclock clock NEVER advances automatically - something I hadn't noticed at first. I thought it was slow.
aasoror
02-08-2011, 11:35 PM
Excellent write up,
Thanks,
I suspect the "drift" is why some of the firmwares have dropped the ability to set the time.
grill
03-20-2011, 06:04 PM
The NTPD work fine, but how did that NTPD refresh automatically every time when I turn on the PBO? :rolleyes:
aasoror
03-20-2011, 09:09 PM
The NTPD work fine, but how did that NTPD refresh automatically every time when I turn on the PBO? :rolleyes:
You can add whatever commands that starts the service to your /usr/local/etc/rcS (startup script).
grill
03-21-2011, 07:01 PM
Thank you! :)
jamaroney
05-21-2012, 11:31 AM
I installed busybox 1.18.1 on my PBO successfully. When I run "ntpd -nq -p pool.ntp.org" via telnet after startup, it works fine, but it doesn't work when I put it in rcS. Am I doing anything wrong, or will it simply not work in the startup script?
snappy46
05-21-2012, 03:11 PM
I installed busybox 1.18.1 on my PBO successfully. When I run "ntpd -nq -p pool.ntp.org" via telnet after startup, it works fine, but it doesn't work when I put it in rcS. Am I doing anything wrong, or will it simply not work in the startup script?
My guess would be that your network connection is not active yet when running from the rcS file. I personnally only have one extra entry in my rcS file to another script which make all the magic happen. The first thing that happen in my script is a loop to make sure my network (wireless/ethernet) is up an running before anything happen. After that loop is completed I then mount my NAS, setup the time, launch lighttpd etc......
Hope this helps!
Cheers!!!
Mr. Gadget
05-21-2012, 05:54 PM
I have a few dirty programs I use to boot my system.
First, I added a call in the rcS1 file to myStartup.sh (see imbedded comment)
Then, myStartup.sh calls all of my utilities to do my system setup:
1) Run setMGWY.sh to determine what the default gateway should be
2) Run chknet.sh to see if the network is operational yet
3) Run getTime.sh to set the time using NTPD
4) Run myMount.sh to mount my SMB shares (not included here)
You may name the programs with our without the .sh, if you add, then be sure to edit the files to include the correct name.
(By default, the only file with .sh is myStartup.sh)
File: myStartup.sh
File: myStartup.sh
#!/bin/sh
# myStartup.sh
# Date: 20110804 V1.21
# Date: 20120103 V1.21b Change from HDD to USB (Mars), Removed SYSLOG and looger (too much memory used)
# Date: 20120521 V1.21c Cleanup
# This program will check the status of the network, if up
# it will set time, mount shares, and whatever else is needed if network up.
# If network down, you can do something else.
# If used in rcS1, be sure to make verbose 0 (no output)
# Expects busybox to be in ???
# Add/Edit your /etc/init.d/rcS1 - (remove comments ##!# below) 120103 (mount -o remount,rw /)
### file rcS1
### Added 120103 - If usb attached. wait till ready, run myStartup commands, else bypass
##!#sleep 20
##!#if [ -e /tmp/usbmounts/sdb1/bin/scripts/myStartup.sh ]; then
### echo "File exists"
##!# /tmp/usbmounts/sdb1/bin/scripts/myStartup.sh&
##!#fi
# Usually, the IP is for the router/gateway
# Programs used:
# Syntax:
# chknet [-i IP|MGWY] [-c count] [-q] [-h]
# getTime [-q]
# setMGWY [-q]
# myMount [-q]
# Start USER DEFINED Programs:
CKNET="/tmp/usbmounts/sdb1/bin/scripts/chknet"
STMGY="/tmp/usbmounts/sdb1/bin/scripts/setMGWY"
GTIM="/tmp/usbmounts/sdb1/bin/scripts/getTime"
MYMNT="/tmp/usbmounts/sdb1/bin/scripts/myMount"
# End USER DEFINED Programs
# Start SYSLOG (too much memory used)
##/etc/init.d/syslog.rcS -p /tmp/hdd/volumes/HDD1/logs/syslog&
#logger " $(date) - Syslog started at boot"
# Locate the Default gateway router, set MGWY variable (this may have trouble - redo to file?)
. $STMGY
# TEMP What is set?
##set
# See if network is operational
$CKNET -q
# Save the exit status of last command
status=$?
if [ $status == 0 ];
then
# Do something if network is UP
##echo "GOOD Status is (0 or 0)" $? " chknet status is " $status
# Set the Time of day from NTP
$GTIM -q
# Mount my SMB shares
$MYMNT -q
#logger " $(date) - MyStartup completed succesfully"
else
# Do something if network is DOWN
##echo "BAD Status is (1 or 100)" $? " chknet status is " $status
logger " $(date) - MyStartup did not complete succesfully, Status: $status"
fi
# and finis
# end myStartup
Next post included files (too long for original post)
Good Luck, hope these help.
Mr. Gadget
05-21-2012, 05:56 PM
Part 2, Utility Files
File: setMGWY
File: setMGWY.sh
#!/bin/sh
# Date: 20110628 v1.1
tver="v1.1"
# By: Mr. Gadget
# Script: setMGWY
# Purpose: Create a Global variable MGWY used other programs, such as:
# chknet, getTime, myMount ...
# Use netstat to locate Gateway, save to temp file, and make global variable MGWY.
# (Others may find faster methods to accomplish same).
# Note: To make variable global (parent shell) use ". path/setMGWY"
#
# Input: None
# Output: Environment variable MGWY
#####################################
# Identify our current gateway. Not sure what it looks like if no network.
netstat -r -n | grep ^0.0.0.0 | awk '{print $2}' >/tmp/mynet.tmp
read MGWY </tmp/mynet.tmp
# Debug echo (uncomment #.#)
#.#echo "MGWY is $MGWY"
export MGWY
# Debug export (uncomment #.#)
#.#export
# end setMGWY
File: chknet
File: chknet.sh
#!/bin/sh
# Date: 20110628 v5.4
# Date: 20110928 v5.4a Modify from HDD to USB - Use Direct link to awk (gawk)
# Date: 20120112 v5.4b awk fixed with MegaPack Update
tver="v5.4b"
# By: Mr. Gadget
# Script: chknet [-i IP] [-c count] [-q] [-h]
# where -i IP = xxx.xxx.xxx.xxx (or $MGWY)
# -c count = 1-n (1=22seconds, 2=33seconds, 3=44...) delay (or $PLOOP)
# -q (quiet, otherwise verbose) (or $VERBOSE=0 or 1)
# Status Returns: 0 if network up, 1 invalid input, 2 invalid BusyBox, 100 if network down
# Purpose:
# This script will loop on checking the network status Up or Down,
# and then return status code 0 for UP and 100 for DOWN.
# The loop count is user selectable to avoid endless loop.
# DO NOT RUN IN VERBOSE MODE within your rcS
# This program REQUIRES the updated BusyBox (V1.16+) command parser
# with the extra PING features.
# Get the advanced Busybox here (save with extension .asc)
# http://busybox.net/downloads/binaries/1.16.1/busybox-mipsel
# also
# http://playon.unixstorm.org/download/tools/busybox1.18.3
# Tip: Make an alias in /etc/profile,
# alias bb="/tmp/hdd/volumes/HDD1/bin/busyboxxxxx.asc"
# for ongoing use of the advanced busybox commands for interactive use.
##### USER-SPECIFICS
# Choices for file locations of your Busybox 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 /tmp/usbmounts/sdb1 (host3 part1 = 8GB, type vfat)
# Removable USB /tmp/usbmounts/sda1 (UNUSED)
# Define where your updated BusyBox image is located (not Flash)
# I use the bin folder on the USB drive for this PBO (in case I need to remove it to bypass my startups)
#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"
# Bug in previous BB. If needed, Use awk file /usr/local/bin/package/awk" (FIXED with MegaPack update)
### Define your default gateway if you want
tmgwy="192.168.1.253"
### Define Default loop count 1=22sec, 2=33sec, 3=44sec ...
tploop=5
### Define Default Verbose (not quiet).
tverbose=1
#### END USER-SPECIFICS
### oh, check to see if we have access to a good BusyBox image, exit error 2 if not found
if [ ! -s "$MBB" ];
then
echo "No path to extended Busybox file"
exit 2
fi
### OK to proceed if updated Busybox available
### Test if input options specified, or use Global vars ($MGWY, $PLOOP, $VERBOSE)
args=`getopt i:c:qh $*`
if test $? != 0
then
echo 'Version: '$tver;\
echo 'Usage: '$0' [OPTIONS]'; echo '';\
echo 'Options:'; echo ' -i IP Check if Host IP is Up/Down'; \
echo ' Global Variable $MGWY may be used.'; \
echo ' -c CNT Loop delay count, [5] = 66 seconds'; \
echo ' Global Variable $PLOOP may be used.'; \
echo ' -q Quiet mode. No output.'; \
echo 'Status:'; echo ' 0 = Host up, 1 = invalid input, 2 = invalid Busybox file, 100 = Host down'
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
-i) opt_i=$2;shift;shift;;
-c) opt_c=$2;shift;shift;;
-q) opt_q=$1;shift;;
-h) echo ''; \
echo 'chknet Version: '$tver;\
echo 'Usage: '$0' [OPTIONS]'; echo '';\
echo 'Options:'; echo ' -i IP Check if Host IP is Up/Down'; \
echo ' Global Variable $MGWY may be used.'; \
echo ' -c CNT Loop delay count, [5] = 66 seconds'; \
echo ' Global Variable $PLOOP may be used.'; \
echo ' -q Quiet mode. No output.'; \
echo 'Status:'; echo ' 0 = Host up, 1 = invalid input, 2 = invalid Busybox file, 100 = Host down'
exit 1
esac
done
### If we did not pass any (-i) IP options, use either the global exported MGWY or assign a gateway.
if [ -n "$opt_i" ];
then
### Do something if TRUE, like save the -i input
###echo "Valid var opt_i=$opt_i, use it"
MGWY=$opt_i
else
### Do something if FALSE, like assign the Global var or a temp IP
###echo "Try if global MGWY=$MGWY, else set to temp gateway"
[ "$MGWY" ] || MGWY="$tmgwy"
fi
### If we did not pass any (-c) COUNT options, use either the global exported PLOOP or assign a value
if [ -n "$opt_c" ];
then
### Do something if TRUE, like save the -c input
###echo "Valid var opt_c=$opt_c, use it"
PLOOP=$opt_c
else
### Do something if FALSE, like assign the Global var or a temp CNT
###echo "Try if global PLOOP=$PLOOP, else set to temp count"
[ "$PLOOP" ] || PLOOP=$tploop
fi
### If we did not pass any (-q) QUIET options then go verbose
if [ -n "$opt_q" ];
then
### Do something if TRUE, like save the -q input
###echo "Valid var opt_q=$opt_q, use it"
VERBOSE=0
else
### Do something if FALSE, like assign the Global var or a temp Verbose
###echo "Try if global VERBOSE=$VERBOSE, else set to VERBOSE"
[ "$VERBOSE" ] || VERBOSE=$tverbose
fi
### debug ###
#.#echo "mgwy " $MGWY
#.#echo "ploop " $PLOOP
#.#echo "verbose " $VERBOSE
### debug ###
### OK, we have all our inputs, lets go to work.
### Setup if Quiet or Verbose. Output logic: NON-VERBOSE = 0 , VERBOSE = 1 (default)
########### WARNING ###########
# DO NOT run this in the /usr/local/etc/rcS with output enabled
# If using as a local script may use -q or not, in rcS, wse -q
########### WARNING ###########
### Make a redirect command for output (if verbose or not)
redir_cmd() {
### Are we verbose(1) or quiet(0)
if [ "$VERBOSE" -eq 0 ];
then
"$@" > /dev/null
else
"$@"
fi
}
### Lets get started - Define a pinger function and then test if target host IP up
# If network up, exit with status 0, otherwise exit with status 100 (failed)
#redir_cmd echo "Target IP = "$MGWY
# Create awk function to use extended busybox ping with cnt feature
## If your version of native awk is broken, use the version in the package directory
##/usr/local/bin/package/awk ' function pinger(count,ip) {
awk ' function pinger(count,ip) {
command = "'$MBB' ping -c "count " " ip
while (( command | getline res )> 0 ) {
if ( res ~ /0 received|100% packet loss/ ) {
close(command)
return 100
} # IF packet loss
} # WHILE ping
close(command)
return 0
} # FUNCTION pinger
BEGIN {
IP="'$MGWY'" # Identify the target host
VERB="'$VERBOSE'" # Verbose?
looper='$PLOOP' # how many iterations to test
if ( VERB == 1 ) { print "Checking host " IP " for " looper " iterations, or unless up" }
if ( pinger(2,IP) == 100 ) {
if ( VERB == 1 ) { printf IP " Not up.." }
c = 0
while ( c < looper ) { # we were not up on first pass, keep trying
if ( pinger(2,IP) == 100 ) {
c=c+1
#if ( VERB == 1 ) { print IP " Not up yet." }
if ( VERB == 1 ) { printf " Not up.." }
} else
{ if ( VERB == 1 ) { print IP " up." }
c=looper
exit 0} # We are up now, so stop while and set exit status
} # While
exit 100 # We are still down
} else {
if ( VERB == 1 ) { print IP " up." }
exit 0 } # If the first pass is good, then we are up
} # BEGIN function pinger begin
END {
if ( VERB == 1 ) { print "Exiting. " $0 }
} # END function pinger end
' # awk end
# Were done here -- How did we do - If 0, then network UP, if 100, then network DOWN
##End chknet
Continued in next post.
Mr. Gadget
05-21-2012, 05:57 PM
Part 3, Utility Files
File: getTime
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).
jamaroney
05-21-2012, 06:27 PM
I'll check this all out - thanks!!
jamaroney
05-22-2012, 12:45 PM
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.
Mr. Gadget
05-22-2012, 03:24 PM
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.
list of timezone
원문 : http://en.wikipedia.org/wiki/List_of_tz_database_time_zones