Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Im trying to run this shell script that is supposed to do this:

  • 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.

I keep getting this error:

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

update.sh: line 9: `fi'

here is the script:

#!/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

Any ideas?

share|improve this question
    
Try #!/bin/bash instead of !/bin/sh. I have been told that there may be problem if the intended shell is not target, or the she-bang is not properly used. Especially if you intend to make it on auto-running scripts like corn-jobs (or some mac-os equivelent). –  Abhinav Kulshreshtha Feb 27 '13 at 18:58
    
it does have the # but for some reason when I typed it into this page it wouldnt show up. –  Ulysses Aguilar Feb 27 '13 at 21:49
    
What about using bash instead of sh. Try it, #!/bin/bash. I never used a real MAC but a few months on hakintosh, I know that zsh or csh is mostly default shell on it. On linux default is bash. –  Abhinav Kulshreshtha Feb 28 '13 at 19:44
    
Woah! Thanks for pointing out this awesome CLI tool softwareupdate. Never knew about it. –  kalaracey Mar 5 '13 at 3:23
add comment

1 Answer

The lines that start with date are missing line continuation characters. Replace them with something like this:

date >> /Library/Management/update.log && /usr/sbin/softwareupdate -aiv >> \
/Library/Management/update.log && /sbin/reboot    
share|improve this answer
    
I still get the same error –  Ulysses Aguilar Feb 28 '13 at 16:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.