Execution Problems with ASU Shell Script

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Execution Problems with ASU Shell Script
# 1  
Old 03-13-2009
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! Smilie

#!/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  
Old 03-15-2009
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  
Old 03-15-2009
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  
Old 03-15-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Script on Solaris spawning 2 processes for one shell script execution

Hi, I am having a shell script on Solaris 10 which has a while loop as shown below. #!/usr/bin/ksh # while do sleep 60 done Name of the shell script is coldcentric.sh. I executed script /DATAWAREHOUSE/LOAD/Scripts/coldcentric.sh from a command task in Informatica worklow as... (3 Replies)
Discussion started by: chekusi
3 Replies

2. Shell Programming and Scripting

Expect script Execution Problems .. Help!!!

Hi Guys, I am writing the expect script which take input from the txt file and check whether that file is present over the Sftp or not.If yes then delete other wise check the next one.. I am able to do comparison online for single file... Please also note still i didn't try to implement... (1 Reply)
Discussion started by: hackerdilli
1 Replies

3. UNIX for Dummies Questions & Answers

shell script execution in ab initio

Hi All, How to execute shell script for running Ab initio graphs? Regards (0 Replies)
Discussion started by: eshalife
0 Replies

4. Shell Programming and Scripting

Execution problems with BASH Shell Script

Hi I need help with my coding , first time I'm working with bash . What i must do is check if there is 3 .txt files if there is not 3 of them i must give an error code , if al three is there i must first arrange them in alphabetical order and then take the last word in al 3 of the .txt files... (1 Reply)
Discussion started by: linux newb
1 Replies

5. UNIX for Advanced & Expert Users

SSH using shell script terminates the script execution

Hello, I am writing a shell script in which i do ssh to remote server and count the number of files there and then exit. After the exit the shell script terminates which i believe is expected behavior. Can some one suggest me a way where even after the exit the script execution resumes. ... (2 Replies)
Discussion started by: manaankit
2 Replies

6. AIX

SH Script Execution Problems with Cronjob

Hi, I have created a sh script to startup and shutdown the oracle database, when I execute the script thru command line it execute successfully, but when I call the script thru cronjob it does not execute. The scripts are as follows: LOG=/oracle/times.log export ORACLE_SID=prod echo... (6 Replies)
Discussion started by: lodhi1978
6 Replies

7. Shell Programming and Scripting

Execution Problems with bash script

Hello, can someone please help me to fix this script, I have a 2 files, one file has hostname information and second file has console information of the hosts in each line, I have written a script which actually reads each line in hostname file and should grep in the console file and paste the... (8 Replies)
Discussion started by: bobby320
8 Replies

8. Shell Programming and Scripting

execution of aliases from shell script

Hi I have to execute the commands in .aliases file from a shell script I tried 1.giving the alias directly in shell script 2.Giving the actually "value of alias" in the shell script 3. I tried giving both steps 1 and 2 inside ` quotes Still nothing is working . It says command... (3 Replies)
Discussion started by: ssuresh1999
3 Replies

9. Shell Programming and Scripting

automatic execution of shell script

Dear All, I want to execute a shell script,whlie system is booting. I was try using /etc/rc.d/rc.local file but its not working. (1 Reply)
Discussion started by: rajamohan
1 Replies

10. Shell Programming and Scripting

execution of shell script

How can I execute another shell script from one? Malay (5 Replies)
Discussion started by: malaymaru
5 Replies
Login or Register to Ask a Question