Browsing Posts in Training

This week I am teaching the LPI 101 course again and we covered the shadow file today (amongst other topics). I gave the students the exercise to manually edit the shadowfile and let an account expire on 01-01-2011. The manpage of shadow(5) stipulates that the account expiration date has to be “expressed as the number of days since Jan 1, 1970″. One of my students asked me how to calcuate this. I did not immediately know the answer and I did not want to use rely on any online date/time converter, so I went looking for a satisfactory solution.

1. Find the UNIX time / Epoch of the date in question

date -d ‘2011-01-01′ +%s

Remember that these are seconds since 01-01-1970.

2. Calculate the number of days since 01-01-1970.

echo `date -d ‘2011-01-01′ +%s` / 86400 | bc

A day is 60 * 60 * 24 = 86400 seconds. Notice how ‘bc’ will always be rounding down the number of days.

3. Perform a ‘normal’  round up or down for the number of days

UNIXTIME=`date -d ‘2011-01-01′ +%s` ; printf “%.0f\n” `echo “scale=1; $UNIXTIME / 86400″ | bc`

Vandaag heb ik het voor het eerst ervaren hoe het is om les te geven. Gelukkig had ik mijzelf goed voorbereid en dit zorgde voor een goede eerste workshop. Verbazingwekkend genoeg waren de studenten zeer gemotiveerd en geinteresseerd in linux. Het leukste moment blijft als ze erachter komen dat het daadwerkelijk makkelijk in gebruik is en dat zodoende een bepaalde scepsis weggehaald wordt.
Wat eventjes voor wat drukte zorgde was dat in het begin toch veel vragen gesteld werden en ik dus van hot naar her mocht huppelen. Dit was ook snel weer voorbij en kon ik nog wat zaken controleren en de sheets van de presentatie online zetten. Al met al een geslaagde dag!