Time output format

Jeff Sadowski jeff.sadowski at gmail.com
Thu Apr 29 01:14:16 CEST 2010


I came up with an elaborate script to check the time and run a command
that was emailed to me. I run this in a cron job every minute.  Maybe
others might find this useful.

<----------------------------------------------------- begin
#!/bin/bash

From="FirstName LastName <email_address at webaddress>"
key="XXXX XXXX XXXX XXXX XXXX  XXXX XXXX XXXX XXXX XXXX"

onemail(){
cat /var/spool/mail/${USER} >> .onemail
echo -n >  /var/spool/mail/${USER}
Next=`grep -n "^From " .onemail|head -n 2|tail -n 1|cut -d: -f1`
if [ "${Next}" = "" ];then
 Next=0
fi
if [ "${Next}" -lt "3" ]; then
 cat .onemail
 echo -n > .onemail
else
 let Next=${Next}-2
 Lines=`wc -l .onemail| cut -d" " -f1`
 let Left=${Lines}-${Next}
 head -n $Next .onemail
 tail -n $Left .onemail > .onemail.tmp
 cat .onemail.tmp > .onemail
 rm -rf .onemail.tmp
fi
}

rlz(){ echo $1|sed 's/^0*//';}

Time(){
 HOUR=`rlz \`echo $1|cut -d: -f1\``
 MINUTES=`rlz \`echo $1|cut -d: -f2\``
 if [ "${MINUTES}" = "" ];then MINUTES=0;fi
 Seconds=`rlz \`echo $1|cut -d: -f3\``
 if [ "${Seconds}" = "" ];then Seconds=0;fi
 if [ "${HOUR}" = "12" ];then HOUR=0;fi
 if [ "$2" = "PM" ]; then let HOUR=${HOUR}+12;fi
 let Seconds=${HOUR}*60*60+${MINUTES}*60+${Seconds}
 echo ${Seconds}
}

leap_year(){
ly=0;let x=$1%400;
if [ "$x" = "0" ];then ly=1 ;else let x=$1%100;
if [ "$x" != "0" ];then let x=$1%4;
if [ "$x" = "0" ];then ly=1;fi;fi;fi
echo ${ly}
}

#day of year
doy()
{
ly=`leap_year $1`;
case "$2" in
1|Jan) let x=$3 ;;
2|Feb) let x=31+$3 ;;
3|Mar) let x=59+$ly+$3 ;;
4|Apr) let x=90+$ly+$3 ;;
5|May) let x=120+$ly+$3 ;;
6|Jun) let x=151+$ly+$3 ;;
7|Jul) let x=181+$ly+$3 ;;
8|Aug) let x=212+$ly+$3 ;;
9|Sep) let x=243+$ly+$3 ;;
10|Oct) let x=273+$ly+$3 ;;
11|Nov) let x=304+$ly+$3 ;;
12|Dec) let x=334+$ly+$3 ;;
esac
let y=365+$ly
echo $x of $y
}

#days of years in between
days_of_yib(){
 if [ $1 = $2 ];then
 echo 0
 elif [ $1 -gt $2 ];then
 let x=$1-$2-1
 if [ ${x} -gt 0 ];then
 let minus_one=$1-1
 let y=365+`leap_year ${minus_one}`+`days_of_yib ${minus_one} $2`
 echo $y
 else
 echo 0
 fi
 else
 days_of_yib $2 $1
 fi
}

days_apart()
{
 one=`doy $1 $2 $3`
 two=`doy $4 $5 $6`
 if [ "$1" = "$4" ];then
 let x=`echo $one $two|awk '{print $1-$4}'`
 echo ${x}
 else
 plus=`days_of_yib $1 $4`
 if [ $1 -gt $4 ];then
 let all=`echo $two $one $plus| awk '{print $7+$4+$3-$1}'`
 else
 let all=`echo $one $two $plus| awk '{print $7+$4+$3-$1}'`
 let all=0-$all
 fi
 echo ${all}
 fi
}

seconds_apart(){
 days=`days_apart \`rlz $1\` \`rlz $2\` \`rlz $3\` \`rlz $6\` \`rlz
$7\` \`rlz $8\``
 let x=`Time $4 $5`-`Time $9 ${10}`+$days*86400
 echo $x
}

seconds_ago(){ seconds_apart `date "+%Y %m %d %I:%M:%S %p"` $1 $2 $3 $4 $5;}

while [ "`cat ${HOME}/.onemail /var/spool/mail/${USER}`" != "" ]; do
 verify=`onemail |gpg 2>&1 1> ${HOME}/.command`
 if [ "`cat ${HOME}/.command`" != "" ];then
 seconds_ago=`seconds_ago \`echo -e "${verify}"|grep "^gpg: Signature made"|
              awk '{print $7 " " $6 " " $5 " " $8 " " $9}'\``
 if [ "$seconds_ago -lt 3600" ]; then
  Good=`echo -e "${verify}"|grep "^gpg: Good signature from"`
  Primary=`echo -e "${verify}"|grep "^Primary key fingerprint:"`
  if [ "${Good}" = "gpg: Good signature from \"${From}\"" ] &&
     [ "${Primary}" = "Primary key fingerprint: ${key}" ]; then
   `cat ${HOME}/.command` &
  else
   echo `date` Bad Signature >> logfile
   echo -e "$verify" >> logfile
fi;fi;fi;done
<-------------------- End

On Tue, Apr 27, 2010 at 2:50 PM, Joke de Buhr <joke at seiken.de> wrote:
> The format of the time stamp can be change according to your locale. Just
> specify an individual setting for LC_TIME.
>
> On Tuesday, 27. April 2010 20:52:58 Jeff Sadowski wrote:
>> when I run something like so
>> "cat test.email |gpg"
>> where test.email is an email that was signed I get output like so
>>
>> <--- begin
>> The verified signed text
>> ...
>> gpg: Signature made <3 letter Day of Week> <Day of Month> <3 letter
>> Month> <year> <time> <AM/PM> <time zone> using DSA key ID <DSA key ID>
>> gpg: <Good|Bad?> signature from "<key sender>"
>> Primary key fingerprint: <Key fingerprint>
>> <--- end
>>
>> Is there an option to change the format of the time?
>> While reading the manual I could not find it.
>>
>> I'd like it in a time stamp format so its easy to compare against current
>> time. Or is there an option to validate that the text was signed within xx
>> hours?
>>
>> _______________________________________________
>> Gnupg-users mailing list
>> Gnupg-users at gnupg.org
>> http://lists.gnupg.org/mailman/listinfo/gnupg-users
>
> _______________________________________________
> Gnupg-users mailing list
> Gnupg-users at gnupg.org
> http://lists.gnupg.org/mailman/listinfo/gnupg-users
>
>



More information about the Gnupg-users mailing list