Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...One of the best run forums I have used in years! ...I like the way the site is organized and your no tolerance of flames..."

Geography

Where in the world do Tek-Tips members come from?

awk file in if statement then statement KSH

hg4372 (TechnicalUser)
14 Jun 12 15:54
if [[ awk '{ print $1 =< 100 }' PERCENT_ALERT.txt ]] ; then

/usr/lib/sendmail -v -f "ALERT" "email@address.com" < ALERT.txt

else

echo "File is Empty"

#echo "File is Empty" | mailx -s "FILE_EMPTY" herb.glaser@uscellular.com

fi;
feherke (Programmer)
15 Jun 12 3:02
Hi

Between the [[ and ]] an expression is expected. And expression != command.

To make your command being executed, enclose it in `...` or $(...).

But probably this will not work as you expected. Better explain your goal and show some sample data from PERCENT_ALERT.txt.

Feherke.
http://feherke.github.com/

hg4372 (TechnicalUser)
15 Jun 12 9:30
Thanks for the help.

The PERCENT_ALERT.txt is a single line file that only has a numeric value as such.

98

hg4372 (TechnicalUser)
15 Jun 12 9:35
Better explanation is if the value in the PERCENT_ALERT.txt file is less than or equal to 100 then send an email with the text of a different file.

Hope that makes sense.
feherke (Programmer)
15 Jun 12 9:44
Hi

If you are sure the file will always contain one integer, then I would prefer this way :

CODE --> (ba|k)sh

if (( $(< PERCENT_ALERT.txt ) <= 100 )); then
/usr/lib/sendmail -v -f "ALERT" "email@address.com" < ALERT.txt
else
echo "File is Empty"
fi
Tested with bash and mksh.

Feherke.
http://feherke.github.com/

hg4372 (TechnicalUser)
15 Jun 12 10:18
It seems to be working as far as the if portion, however it this is in a KSH script.

When it meets the criteria of the if statement I get several emails in a row with nothing in them other then ALERT as the subject.

if (( $(< PERCENT_ALERT.txt ) <= 100 )); then

/usr/lib/sendmail -v -f "ALERT" "email@address.com" < ALERT.txt

else

echo "File is Empty"

fi;

Not sure why it repeats itself over and over ??? And not including the ALERT.txt information.
feherke (Programmer)
15 Jun 12 10:24
Hi

Interesting. What happens when you move the reading of PERCENT_ALERT.txt out from the if condition ?

CODE

percent=$(< PERCENT_ALERT.txt )

if (( percent <= 100 )); then
/usr/lib/sendmail -v -f "ALERT" "email@address.com" < ALERT.txt
else
echo "File is Empty"
fi

Feherke.
http://feherke.github.com/

hg4372 (TechnicalUser)
15 Jun 12 11:11
Still get about 9 emails with only a subject.
feherke (Programmer)
15 Jun 12 11:43
Hi

Let us add some debugging. Please post the output produced by this script :

CODE

percent=$(< PERCENT_ALERT.txt )
echo "percent='$percent'"

if (( percent <= 100 )); then
echo 'percent is small'
else
echo 'percent is big'
fi

if (( percent <= 100 )); then
echo 'before send'
/usr/lib/sendmail -v -f "ALERT" "email@address.com" < ALERT.txt
echo 'after send'
else
echo "File is Empty"
fi

Feherke.
http://feherke.github.com/

hg4372 (TechnicalUser)
15 Jun 12 12:07
percent='99'
percent is small
before send
email@address.com... Connecting to corpmta.com. via relay...
220 wimidd01-smtp-01-internal.com ESMTP
>>> EHLO ilscha01-nsweng-01.com
250-wimidd01-smtp-01-internal.com
250-8BITMIME
250 SIZE 16777216
>>> MAIL From:<ALERT@ilscha01-nsweng-01.com> SIZE=36
250 sender <ALERT@ilscha01-nsweng-01.com> ok
>>> RCPT To:<email@address.com>
250 recipient <email@address.com> ok
>>> DATA
354 go ahead
>>> .
250 ok: Message 408188946 accepted
email@address.com... Sent (ok: Message 408188946 accepted)
Closing connection to corpmta.com.
>>> QUIT
221 wimidd01-smtp-01-internal.com
after send
feherke (Programmer)
15 Jun 12 12:15
Hi

Looks correct for me.

And if you run only the sendmail command without the rest of the script, still get multiple mails ?

Feherke.
http://feherke.github.com/

hg4372 (TechnicalUser)
15 Jun 12 12:37
/usr/lib/sendmail -v -f "ALERT" email@address.com < ALERT.txt

I only get 1 email when I do this, however I only see ALERT in the sender information. No information from the ALERT.txt file is included.

I was including the if statement at the end of a cron that runs every five minutes. However every five minutes I was getting 9 emails.

Crazy.
feherke (Programmer)
15 Jun 12 12:53
Hi

Could you show us more from that script ? Maybe the relevant crontab line(s) too.

Feherke.
http://feherke.github.com/

hg4372 (TechnicalUser)
15 Jun 12 13:38
I have a get_script that kicks off the other script. The reason is I'm pulling the same data from several places at once ever 5 minutes.

CRON Entry
1,6,11,16,21,26,31,36,41,46,51,56 * * * * /export/home/scripts/get_mtxcper

cat get_mtxcper
/export/home/scripts/mtxcper STLOMTX &

cat mtxcper
#!/usr/bin/ksh
# echo "Enter switch: \c"
# read switch
# echo "Enter username: \c"
# read username
# echo "Enter password: \c"
# read password
switch=$1
dt=$(date +%m%d%y_%H%M)
username=username
password=password

for x in 1
do
{
sleep 5
echo $username
sleep 3
echo $password
sleep 3
echo "get cper"
sleep 3
echo "exit;"

}|telnet $switch>/export/home/live/cperlive/$switch.txt

done

tail +45 /export/home/live/cperlive/STLOMTX.txt > /export/home/live/cperlive/STLOMTX.LIVE.txt

cat /export/home/live/cperlive/STLOMTX.txt | grep "BHCA" > /export/home/live/cperlive/BHCA.txt

cat /export/home/live/cperlive/STLOMTX.txt | grep "Origination" > /export/home/live/cperlive/Origination.txt

awk '{ print $4, $NF }' < /export/home/live/cperlive/BHCA.txt > /export/home/live/cperlive/CPER_ALERT.txt

awk '{ print $2, $3 }' < /export/home/live/cperlive/Origination.txt >> /export/home/live/cperlive/CPER_ALERT.txt

cat /export/home/live/cperlive/Origination.txt | grep "Voice" > /export/home/live/cperlive/voice.txt

awk '{print $3 }' < /export/home/live/cperlive/voice.txt > /export/home/live/cperlive/percent.txt

sed 's/%//' /export/home/live/cperlive/percent.txt > /export/home/live/cperlive/PERCENT_ALERT.txt

percent=$(< /export/home/live/cperlive/PERCENT_ALERT.txt )

echo "percent='$percent'"

if (( ( percent ) <= 100 )); then

/usr/lib/sendmail -v -f "CPER_ALERT" "email@address.com" < /export/home/live/cperlive/CPER_ALERT.txt

else

echo "File Not Found"

fi;

hg4372 (TechnicalUser)
22 Jun 12 11:16
I figured out the issue. Apparently the file I wanted to be included in the email can't have () or : in it. Once I removed those the script works fine.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close