Artificial intelligent assistant

BusyBox date: retrieve date from the internet without ntpdate Embedded poky linux, no `ntpdate` available. It looks like none of the following commands is suitable: # date -s "$(curl -s --head | grep '^Date:' | cut -d' ' -f 3-)" date: invalid date '08 Mar 2021 13:22:34 GMT' # date -s "$(curl -s --head | grep '^Date:' | cut -d' ' -f 3-6)" date: invalid date '08 Mar 2021 13:22:34' #date +"%d %b %Y %H:%M:%S" -s "$(curl -s --head | grep '^Date:' | cut -d' ' -f 3-6)" date: invalid date '08 Mar 2021 13:22:34' # UPDATE BusyBox date only accepts the following date formats: @seconds_since_1970 hh:mm[:ss] [YYYY.]MM.DD-hh:mm[:ss] YYYY-MM-DD hh:mm[:ss] [[[[[YY]YY]MM]DD]hh]mm[.ss] If the `-D` option is available in the BusyBox version you are using, you can use this command as suggested by steeldriver: busybox date -d '08 Mar 2021 13:22:34' -D '%d %b %Y %H:%M:%S'

In the end I parsed the time string from google to put it in a `busybox date` friendly format (`YYYY-mm-dd HH:MM:SS`). Hopefully someone will find this useful in the future.


#!/bin/sh

monthnumber() {
month=$1
months="JanFebMarAprMayJunJulAugSepOctNovDec"
tmp=${months%%$month*}
month=${#tmp}
monthnumber=$((month/3+1))
printf "%02d\
" $monthnumber
}

G_DATE="$(curl -s --head | grep '^Date:' | cut -d' ' -f 3-6)"
G_SPLIT=($(echo $G_DATE | tr " "))

BB_DATE="${G_SPLIT[2]}-$(monthnumber ${G_SPLIT[1]})-${G_SPLIT[0]} ${G_SPLIT[3]}"

date -s "$BB_DATE"


`monthnumber()` function was taken from <

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 8c7ef9509cdd3109f06bbb292688122a