Monday 7 September 2015

... shutdown a system at specific time

I need to shutdown a server at a specific hour a few days from now.  The command shutdown allows to specify the hour but the day so that can't be used.  It also allows to specify a number of minutes from "now" which implies computing that value.  So the following can be used:

sudo shutdown -h +$(($(($(date -d 'yyyy-mm-dd hh:mm:ss' +"%s") - $(date +"%s"))) / 60))

There is also the at command but I'm sure how that well that work with commands that would require sudo.