mercredi 22 juillet 2015

remotely shutting down a linux computer when no user is logged in

I wrote a small script to update a number of Linux computers daily (among other things, which is why a cron job will not do). It is meant to run at night and ssh into each client, update it and shut it down if no other user is logged in. The solution I've come up with is this:

ssh "$value" 'apt-get update && apt-get -y upgrade && if [ $(who | wc -l) != 1 ] ; then exit; else poweroff; fi;' >> "/var/log/updates/$value.log"

When running the script I get Syntax error near unexpected token 'then'. Any help is appreciated

Aucun commentaire:

Enregistrer un commentaire