Need help running this .sh script?

Discussion in 'iMac' started by uly609, Feb 28, 2013.

  1. uly609 macrumors newbie

    Joined:
    Feb 28, 2013
    #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??
     
  2. Brian Y macrumors 68040

    Joined:
    Oct 21, 2012
    #2
    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?
     
  3. uly609 thread starter macrumors newbie

    Joined:
    Feb 28, 2013
    #3
    I not much of a programmer/scripter could you elaborate a little more?
     
  4. uly609 thread starter macrumors newbie

    Joined:
    Feb 28, 2013
    #4
    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?
     

Share This Page