My script does not work - could you pls help?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My script does not work - could you pls help?
# 1  
Old 06-29-2007
My script does not work - could you pls help?

Hi all,
I put together a script that seems not working as I would like to and after spending hours to find the problem I decided to ask your help.
The thing I am trying to do is call AWK command on the TRUE branch of if statement. Else branch should only print out a message to screen.

This is the code I am using:


...
for printer in "$@" ; do
lpstat $printer|grep $printer |grep '-' >$TEMP_FILENAME
grep '-' $TEMP_FILENAME
status=$?
if [[$status -eq 0]] ; then
awk '
{
here I do some stuff...
}
' $TEMP_FILENAME
else
echo "No jobs in the printer queue $printer ..."
fi
done


The result I got is not what I expect:
printerjob1 user priority 0 Jun 27 08:26
printerjob2 user priority 0 Jun 28 13:38
./prg.sh[103]: [[0: not found
No jobs in the printer queue printername ...


So for me it seems program executes somehow both branches of the IF statement.
The line 103 where the problem is indicated is:
if [[$status -eq 0]] ; then

I could not solve it , so please recommend me what the problem might be...

Thank you!
BearCheese
# 2  
Old 06-29-2007
Leave a space before $status and after 0
Code:
if [[ $status -eq 0 ]] ; then

If you have q option with grep which gives the exit status, try this
Code:
if grep -q '-' $TEMP_FILENAME ;then 
awk '
{ 
here I do some stuff...
}
' $TEMP_FILENAME

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

2. Shell Programming and Scripting

Need help with first shell script pls.

Hi, I'm trying to extract information from one file to update another one and am a bit stuck. the first file is made up of tags e.g. <item>a@b.com</item> jksdhfjkdsh sldkjfds l klsjdf <item> c@d.com </item> what i'd like to do is extract the email addresses between these tags,... (6 Replies)
Discussion started by: newb1000
6 Replies

3. Shell Programming and Scripting

Need to understand the script pls help

Can u please explain what it is doing #!/bin/sh fullyear=`/home/local/bin/datemmdd 1`"."`date +%Y` uehist=/u05/home/celldba/utility/ue/prod/history echo $fullyear cd $uehist ls -ltr pwroutages.master.$fullyear* | awk '{print $9}' > /u01/home/celldba/tmp/pwroutages_master_all_tmp while... (2 Replies)
Discussion started by: raopatwari
2 Replies

4. Shell Programming and Scripting

sed replace not work Pls. help me

sed replace not work Pls. help me I used sed command in my file 66875964560@1982589 90825890001@90825890001@3@15/12/2007 14:25:14@22/03/2010 6:06:13@20/01/2010 3:28:39 66873064490@1925912 90259120001@90259120001@5@02/04/2009 1:51:31@30/10/2009 3:08:34@13/09/2009 8:24:33... (3 Replies)
Discussion started by: ooilinlove
3 Replies

5. Shell Programming and Scripting

Pls comment on my script.

Hi guys, hope you scripting gurus here can help me out, the logic in my script somehow not working the way it should, this script part of a bigger backup script suppose to do some checking on the cluster prior to bringing up the package on MC/SG after backend cloning operation, this portion is... (3 Replies)
Discussion started by: sparcguy
3 Replies

6. Shell Programming and Scripting

shell script, pls help

# for i in `cat oo`;do ls -ld $i;done ls: /var/tmp/i: No such file or directory ls: i: No such file or directory ls: /var/tmp/ii: No such file or directory ls: i: No such file or directory ls: /var/tmp/iii: No such file or directory ls: i: No such file or directory ls: /var/tmp/iiii: No such... (2 Replies)
Discussion started by: cpttak
2 Replies

7. Shell Programming and Scripting

Script changes required...Pls. help me!!

Hi All, I'm giving input of four variable. I'm using this script for network field, so I'm defining the example on the same way. Example Input: $1 =ind00m1 $2=Gi1/1 $3=10.0.0.1 $4=Connectivity from 1 to 2 Applies to following line: object=$2 msg_grp=SNMP node=$1 msg_text="IF Down $2 $3... (2 Replies)
Discussion started by: ntgobinath
2 Replies

8. UNIX for Advanced & Expert Users

cp script error, pls help in debugging!!!!

Hi all, I searched to find out a few cp scripts that had progress bar, but did not compromise on performance, when my efforts were in vain i went ahead and wrote one of my own ,taking i/p frm other scripts... But this is causing some errors and am unable to debug it.....pls help Here is the... (1 Reply)
Discussion started by: wrapster
1 Replies

9. Shell Programming and Scripting

Pls. Help my script not working as it should

I'm using nested for loops to gather ping IP addresses from a hostlist and also changing the packet size via a packet size list. The final results of (RTT and SDEV) will need to be grep'd out using awk into variables and then printed in columns (the packet sizes going across with IP address going... (1 Reply)
Discussion started by: cocoabeauty1
1 Replies

10. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies
Login or Register to Ask a Question