Long story short: I'm managing lab Macs and they're always supposed to automatically login to a public account. Over the past few months I've found that some computers would randomly be at the login screen (either because a user tells it to go to the login window or because of problems with logging in/out), and I wanted to make a script to tell a computer to reboot if it's at the login window (which I'd build into a package and scope to recurring check-in).
Right now I have:
#!/bin/bash -v
#get loggedinuser
loggedInUser="$(/bin/ls -la /dev/console | /usr/bin/cut -d " " -f 4)"
#make sure publicaccount logged in
if [[ $loggedInUser != "publicaccount" ]]
then
echo "publicaccount not logged in, restarting"
osascript -e 'tell app "System Events" to restart'
exit 0
else
echo "publicaccount logged in"
exit 1
fi
The part where it detects publicaccount is not logged in works fine, but I can't figure out what command I would need to use to have it restart. I don't think "Finder" or "loginwindow" would work as the app that's being told, and I've tried a few different combinations of restart and «event aevtrlgo» but I keep getting vague error messages, most recently "28:35: execution error: An error of type -10810 has occurred. (-10810)"
Any ideas of what command I would need to use to restart at the login window? Would also need to bypass the "Enter administrator password" window.