LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2006, 12:07 AM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
bash script problem


I have got a script which is not doing what it's
supposed to do.

In short, the script should grep the output of a
program, awk for one column & send an email to me if
anything from that column matches my criteria.

Code:
#!/bin/bash

BINARY="/usr/sbin/binary"
MAIL="/bin/mail"
RECPT="me@yahoo.co.uk"

SUB1="Number does match for `hostname`"
SUB2="Number doesn't match for `hostname`"

ERROR_VALUE="Please try again later"

# grep for specific column
PROG1="`$BINARY -l | grep -n 1 | awk {'print $7'}`"

# mail me to let me know that it is not working
PROG_ERR="`$BINARY -l | $MAIL -s "$SUB2" $RECPT`"

# mail me to let me know that it is working
PROG_OK="`$BINARY -l | $MAIL -s "$SUB1" $RECPT`"

# the total outout
PROG3="`$BINARY -l`"

# conditions
	if [ "$PROG1" = "0.00" ] || [ "$PROG1" -gt "1000" ]
|| [ "$PROG" = "1000" ]; then
	echo $PROG_ERR
	elif [ "$PROG3" == "$ERROR_VALUE" ]; then
	echo $PROG_ERR
	else
	echo $PROG_OK
fi
The program should scan all 3 or 4 lines in the column and grep for 0.00 or 1000 if there is any.

Any kind of help would be appreciated.
 
Old 01-21-2006, 05:02 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Quote:
[ "$PROG" = "1000" ]
You have no $PROG variable in your script...

Also:
Code:
`$BINARY -l | grep -n 1 | awk {'print $7'}`
Here you are grepping for "1". This will match "1000" but not "0.00"

Last edited by bulliver; 01-21-2006 at 05:08 PM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with bash script. cheater1034 Programming 9 11-21-2005 10:29 PM
bash script problem fatbastard spice Linux - General 2 08-24-2005 02:15 AM
[bash] problem with a script MD3 Linux - Software 3 04-05-2005 01:49 PM
bash script problem cookie_ie Programming 3 03-23-2005 02:19 PM
Bash script problem kalleanka Programming 2 01-30-2004 11:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration