![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| OS X (Apple) OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| automatic execution of shell script | rajamohan | Shell Programming and Scripting | 1 | 09-29-2008 06:48 AM |
| problem with shell script execution | anju | Shell Programming and Scripting | 2 | 05-08-2008 01:50 AM |
| Sequential execution in shell script? | chengwei | UNIX for Dummies Questions & Answers | 6 | 03-30-2007 12:10 AM |
| Scheduling the execution of a shell script | sumesh.abraham | Shell Programming and Scripting | 1 | 12-06-2006 07:25 AM |
| execution of shell script | malaymaru | Shell Programming and Scripting | 5 | 06-13-2005 09:49 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Execution Problems with ASU Shell Script
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 |
|
||||
|
It probably won't make a huge difference, but you can skip the "set" command, I believe.
varname=`blah-blah...` is a valid variable declaration. Typically, I will have a development machine that I test on, and when confronted by issues running a specific script, I use the system log to determine why a script is failing. The "logger" command can be used effectively: logger "Software update status: $applesw" ... loggedin=`who | grep 'console' | awk '{print $1}'` logger "Users logged in: $loggedin" Actually, you appear to be using command line substitution in setting up your variables, but you are using double quotes instead of the backtick ` |
|
||||
|
Thank you very much for your input. I have taken what you have suggested and implemented it. When Crontab runs and executes my script, this is what it logs:
Mar 15 21:57:33 ecsxloan1 root: Software update status: '\nfollowing' Mar 15 21:57:33 ecsxloan1 root: Users logged in: '' Also, when I sent the scripts as a Unix command thru Apple Remote Desktop, this is what I received: /Library/Management/initswupdater2.sh: line 16: syntax error near unexpected token `else' /Library/Management/initswupdater2.sh: line 16: `else' It seems to get hung-up at this and then not perform the rest of the script. Any suggestions? |
|
||||
|
This is how my code appears now:
#!/bin/sh applesw=`/usr/sbin/softwareupdate -l | grep 'Software Update' | awk '{print $5}'` logger "Software update status: '$applesw'" loggedin=`who | grep 'console' | awk '{print $1}'` logger "Users logged in: '$loggedin'" if [ $applesw != "following" ] then exit 0 else if [ $loggedin = "console" ] then 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."' softwareupdate -i -a shutdown -r now fi fi |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|