I'm trying to read a string from a file and then convert it into a date but for some reason it's failing. I'm actually modifying a GeekTool Geeklet that's not working at the moment. It reads a file locally and pulls out a target date that is then used in a countdown clock. The line of code that is failing is:
TARGET=$(date -j -f %D_%T $1 +%s)
I know that I can hardcode the value in the script using -v but I want to work out why this line isn't working. I can't seem to find any refs to converting a string from a file into a date object. I also can't find refs to -j or -f flags...
[edit] Here's the full script:
#!/bin/bash
# Homework countdown
# BETA - I will update this when I get more time
function countdown
{
CURRENT=$(date +%s)
TARGET=$(date -j -f %D_%T $1 +%s)
LEFT=$((TARGET-CURRENT))
WEEKS=$((LEFT/604800))
DAYS=$(( (LEFT%604800)/86400))
HOURS=$(( (LEFT%86400)/3600))
MINS=$(( (LEFT%3600)/60))
SECS=$((LEFT%60))
lblWEEKS="Weeks"
lblDAYS="Days"
if [ $DAYS == 1 ]
then
lblDAYS="Day"
fi
if [ $WEEKS == 1 ]
then
lblWEEKS="Week"
fi
if [ $HOURS -lt 10 ]
then
HOURS=0$HOURS
fi
if [ $MINS -lt 10 ]
then
MINS=0$MINS
fi
if [ $SECS -lt 10 ]
then
SECS=0$SECS
fi
echo $1
echo $TARGET
echo $2 $WEEKS Weeks, $DAYS $lblDAYS $HOURS:$MINS:$SECS
# Optional extra line between timers
echo
}
DATES=( $( cat /Users/Shared/Deadlines.txt ) )
# Even numbered indices are names, odd numbered indices are dates
if [ ${#DATES[@]} == 0 ]
then
echo "No Deadlines!"
return
fi
for (( i = 0 ; i < ${#DATES[@]} ; i+=2 ))
do
countdown ${DATES[i+1]} ${DATES[i]}
done
And the file simply contains: test: 17/05/2011_12:00
-jis not present inGNU date, whatdateare you using?