Hello. I have been trying to create a shell script that checks to see if there are software updates and if not, then exit the script. If so, then check to see if a user is logged in. If a user is logged in, it will only install the updates. If a user is not logged in, then it will display a message for the user not to login until that pop-up is gone, then it will install all software updates and reboot the machine.
The script is executed via a Cron Job. It seems to not execute after the variables are declared. Here is the code I have. Any help in this matter is greatly appreciated!
#!/bin/sh
set applesw="/usr/sbin/softwareupdate -l | grep 'Software Update' | awk '{print $5}'"
set userlogin="who | grep 'console' | awk '{print $2}'"
if [ $applesw != "following" ] then
exit 0
else
if [ $userlogin = "console" ] then
/usr/sbin/softwareupdate -i -a
exit 0
else
/usr/bin/osascript -e 'tell app "System Events" to display dialog "Software Updates are currently running. Please do not login to this machine until this message is gone. Thank you."'
/usr/sbin/softwareupdate -i -a
/sbin/shutdown -r now
fi
fi