Skip to content

Instantly share code, notes, and snippets.

@gschueler
Created August 25, 2015 16:37
Embed
What would you like to do?
#!/bin/bash
#determine h:m:s to run, 10 seconds from now
ORIG_DATE=$(date '+%s')
echo "orig: $ORIG_DATE"
NEW_DATE=$(( $ORIG_DATE + 10 ))
echo "new: $NEW_DATE"
print_schedule(){
local DATE=$1
osname=$(uname)
if [ "Darwin" = "$osname" ] ; then
NDATE=$(date -r "$DATE" '+%Y %m %d %H %M %S')
else
NDATE=$(date --date="@$DATE" '+%Y %m %d %H %M %S')
fi
NY=$(echo $NDATE | cut -f 1 -d ' ')
NMO=$(echo $NDATE | cut -f 2 -d ' ')
ND=$(echo $NDATE | cut -f 3 -d ' ')
NH=$(echo $NDATE | cut -f 4 -d ' ')
NM=$(echo $NDATE | cut -f 5 -d ' ')
NS=$(echo $NDATE | cut -f 6 -d ' ')
cat <<END
<schedule>
<time hour='$NH' seconds='$NS' minute='$NM' />
<month month='$NMO' day='$ND' />
<year year='$NY' />
</schedule>
END
}
print_schedule $ORIG_DATE
print_schedule $NEW_DATE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment