The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > OS X (Apple)
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-13-2009
Talcon Talcon is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 3
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
  #2 (permalink)  
Old 03-15-2009
[MA]Flying_Meat [MA]Flying_Meat is offline
Registered User
  
 

Join Date: Sep 2002
Location: San Fran
Posts: 130
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 `
  #3 (permalink)  
Old 03-15-2009
Talcon Talcon is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 3
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?
  #4 (permalink)  
Old 03-15-2009
Talcon Talcon is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 3
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0