Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

uly609

macrumors newbie
Original poster
Feb 28, 2013
4
1
Im trying to run a script that is supposed to:

-This script uses the softwareupdate program on OSX to automatically check for updates and install them. It also logs all updates to the /Library/Management/update.log file.

-It first checks to see if there are any users logged in, and if so, logs the user in the log file and ends.

-If there is no user logged in, it updates the computer, logs the information, and reboots.

Here is the script:

Code:
#!/bin/sh
users=$(users)
users1=$(echo "${#users}")
if [ $users1 -lt 1 ]
then
date >> /Library/Management/update.log && /usr/sbin/softwareupdate -aiv >> /Library/Management/update.log && /sbin/reboot
else
date >> /Library/Management/update.log && echo "Logged in users: " >> /Library/Management/update.log && echo $(users) >> /Library/Management/update.log
fi

I have tried it on 4 iMacs running 10.6.8 and 10.7.4 and I keep getting this error:

Code:
update.sh: line 9: syntax error near unexpected token `fi'

update.sh: line 9: `fi'

Any ideas??
 
Works fine here. Have you checked for any non-unicode characters/spaces in the lines?

Although from a dev point of view - that's very bad practice. What happens if someone logs in between softwareupdate and reboot?
 
What version of OS X are you on? I re wrote it from scratch and now it says it cant find the directory. Im on 10.7.4. Would you happen to know where the update logs are kept on 10.7.4?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.