Hello,
I am trying to set up an el-cheapo attendance system that only calculates how late the person has come with reference to a fixed office time. I don't want to use any database+server thing as that is complex and users are less than 20. I am thinking of a simple approach with cheap and simple biometrics to prevent impersonation. A cheap web cam will click light thumbnails and a timestamp will be generated. Every month a file will be generated after which the photos can be erased automatically. The result file will be a .csv one that can be imported in any Office application.
I am stuck at the point of calculating time difference. There doesn't seem to be a direct command that will calculate time difference in HH:MM format. This link mentions a work around http://www.cyberciti.biz/faq/shell-script-to-get-the-time-difference/ but it first converts time into %s which is the number of seconds since 1970. However every day for the fixed opening time, say 10:00 this figure is not constant. One way out is that every day the %s figure is generated at exactly 10:00 and this is then 'diff'ed with the user's attendance time in %s. This is then divided by 60.
Is there a simpler bash command that I may have overlooked that simply takes in 10:17 and 10:00 and says 00:17?
2011/3/21 Rony gnulinuxist@gmail.com:
I am stuck at the point of calculating time difference. There doesn't seem to be a direct command that will calculate time difference in HH:MM format. This link mentions a work around
Even if you find one, remember that such a command would be internally converting to seconds-since-epoch and then doing the arithmetic.
figure is not constant. One way out is that every day the %s figure is generated at exactly 10:00 and this is then 'diff'ed with the user's attendance time in %s. This is then divided by 60.
You don't need to do that. You can simply do:
late=$(( `date '+%s'` - `date '+%s' -d 'today 10am'` ))
And then convert $late to any format you want.
Binand
2011/3/21 Binand Sethumadhavan binand@gmail.com:
late=$(( `date '+%s'` - `date '+%s' -d 'today 10am'` ))
And then convert $late to any format you want.
Like:
late=$(( `date '+%s'` - `date '+%s' -d 'today 10am'` )) printf "%02d:%02d\n" $(( $late / 60 )) $(( $late % 60 ))
Binand
On Mon, Mar 21, 2011 at 9:28 PM, Binand Sethumadhavan binand@gmail.comwrote:
2011/3/21 Rony gnulinuxist@gmail.com:
figure is not constant. One way out is that every day the %s figure is generated at exactly 10:00 and this is then 'diff'ed with the user's attendance time in %s. This is then divided by 60.
You don't need to do that. You can simply do:
late=$(( `date '+%s'` - `date '+%s' -d 'today 10am'` ))
And then convert $late to any format you want.
Thanks for the tip. I am pasting my code below which works. I will now tweak it with your code above. In the code below, 'cat ten' refers to the file 'ten' which is supposed to be updated everyday at 10.00 AM with date +%s but now won't be needed. The script was made and tested on my netbook and uses the in-built camera. The result is a tiny stamp sized photo uses only 1 KB of space. Cheap bio-metrics.
#!/bin/bash DATE=$(date) CUR=$(date +%s) REF=$(cat ten) streamer -c /dev/video0 -b 16 -q -o testuser.jpeg convert testuser.jpeg -resize 60x40 testuser.jpeg DIFF=$(( $CUR - $REF )) MIN=$(($DIFF/60)) echo " $DATE, Testuser, $MIN," >> Testuser_log.csv exit