A set of POSIX* shell scripts designed for personal use. No guarantees when it comes to quality, as these are also used for various minor experiments of mine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

#!/bin/sh -e
# Retrieve a header from somewhere. Don't care where.
echo "GET HTTP/1.1" | ncat --ssl 443 | grep Date > /tmp/date.jnk
# Month lookup table. Horrible, but I don't know a better method...
# Please forgive me for this sin, Patriarch Bourne.
month=`cut -d ' ' -f 4 /tmp/date.jnk`
case "$month" in
Jan) month=01 ;;
Feb) month=02 ;;
Mar) month=03 ;;
Apr) month=04 ;;
May) month=05 ;;
Jun) month=06 ;;
Jul) month=07 ;;
Aug) month=08 ;;
Sep) month=09 ;;
Oct) month=10 ;;
Nov) month=11 ;;
Dec) month=12 ;;
for each in day year time
export $each=`cat /tmp/date.jnk | tr ' ' '\n' | grep -E [0-9] | sed s/\://g | tr '\n' ' ' | cut -d ' ' -f $x`
printf "The current time is as follows.\nYear: $year\nMonth: $month\nDay: $day\nTime: $time\n"
time=`echo $time | cut -b 1,2,3,4`
year=`echo $year | cut -b 3,4`
printf "Your date-compatible string for today is: $month$day$time$year\nHere it is again, on its own line:\n$month$day$time$year\n"
date -u $month$day$time$year
rm /tmp/date.jnk