awk command with if & mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command with if & mail
# 8  
Old 04-30-2015
Please post a - reasonably truncated - representative sample of your input file.
# 9  
Old 05-02-2015
Hi Rudic Sir,

Thanks for your continuous support, Now again this is not giving any output or mail even though it met with condition .
I have attached the input file inputfile.txt (4.6 KB).
I have tried the below script, I am trying to search BHU file which is in column 3 & also the value which is in column 10 greater or equal than 500 in inputfile.txt file.
But there is no putput or mail is coming. I have also tried to print $TMP & $FILE file also , it is giving the $file output but $TMP there is no value.
I am very new to scripting , please help me.

Code:
LOGDIR=/file/logs/
export MAIL_LIST=shiva@gmail.com
FILE="$(find $LOGDIR -name "*.txt" -type f|sort -r|head -n1)"
awk '$3 == "BHU" && ($10+0)>= 500 { print $3" is running in "$1" from last "$10" secs"; exit 1}' FS="," "$FILE" >TMP || { mail -s "test mail" ${MAIL_LIST} <TMP; }
print $TMP
print $FILE

# 10  
Old 05-03-2015
OK, try by dropping the FS=",". Now you have supplied the sample I can see that space (the default) is the field separator.
# 11  
Old 05-03-2015
Hi Rudic Sir,

I have tried what you have suggested, but it is mailing only first row of all the rows which are having more than 500 values.
means if in input file if there are 5 BTC which are having above 500 , it is mailing only first row ,other rows are not coming in mail.
Code:
#!/bin/ksh
LOGDIR=file/logs
export MAIL_LIST=shyam@gmail.com
FILE="$(find $LOGDIR -name "*.txt" -type f|sort -r|head -n1)"
awk '($3 == "BTC") && (($10+0) >=500) {print $3" is running in "$1" from last "$10" secs";exit 1}' "$FILE" > TMP || { mail -s "test mail" ${MAIL_LIST} <TMP; rm TMP; }

# 12  
Old 05-03-2015
Quote:
Originally Posted by dravi_laxmi
Hi Rudic Sir,

I have tried what you have suggested, but it is mailing only first row of all the rows which are having more than 500 values.
means if in input file if there are 5 BTC which are having above 500 , it is mailing only first row ,other rows are not coming in mail.
Code:
#!/bin/ksh
LOGDIR=file/logs
export MAIL_LIST=shyam@gmail.com
FILE="$(find $LOGDIR -name "*.txt" -type f|sort -r|head -n1)"
awk '($3 == "BTC") && (($10+0) >=500) {print $3" is running in "$1" from last "$10" secs";exit 1}' "$FILE" > TMP || { mail -s "test mail" ${MAIL_LIST} <TMP; rm TMP; }

Then remove the ;exit shown in red above.
# 13  
Old 05-04-2015
It's not quite that easy; we need to transport the FOUND to the END section:
Code:
awk '($3 == "BHU") && (($10+0) >=500) {print $3" is running in "$1" from last "$10" secs"; FOUND=1} END {exit FOUND}' /tmp/inputfile.txt > TMP || { mail -s "test mail" ${MAIL_LIST} <TMP; rm TMP; }

We could of course now flip the logics to run mail:
Code:
awk '($3 == "BHU") && (($10+0) >=500) {print $3" is running in "$1" from last "$10" secs"; FOUND=1} END {exit 1-FOUND}' /tmp/inputfile.txt > TMP && { mail -s "test mail" ${MAIL_LIST} <TMP; rm TMP; }

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Script to ZIP/SAVE & then DELETE Log file & send a mail conformation for any error

ENVIROMENT Linux: RHEL 6.4 Log Path: /usr/iplanet/servers/https-company/logs Log Format: user.log.03-15-2015 I have log4j log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I need a script that will run daily that... (1 Reply)
Discussion started by: admin_job_admin
1 Replies

2. Shell Programming and Scripting

Different output for awk command on Linux & HP-UX

I am using an awk command to extract a particular portion of a string. Below is the command and its output on a Linux system: oracle@host1:/tmp (/home/oracle) $uname -a Linux host1 2.6.32-279.39.1.el6.x86_64 #1 SMP Fri Nov 15 05:38:26 EST 2013 x86_64 x86_64 x86_64 GNU/Linux ... (7 Replies)
Discussion started by: veeresh_15
7 Replies

3. Homework & Coursework Questions

Creating a function that sends a mail using mail command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The function will be called m and it will allow you to send an email to someone using the mail command. The... (1 Reply)
Discussion started by: Drucian
1 Replies

4. Shell Programming and Scripting

[Solved] BASH - chaining TEST and COMMAND with && and II

Can you explain what this line of script is doing. What I have understood is : -- variable C is the name of a software which is either not installed, so it must be installed or allready installed and then should be update if newer version found -- branch B="$B $C" is to install the software --... (4 Replies)
Discussion started by: jcdole
4 Replies

5. Shell Programming and Scripting

Problem Using If & For loop in AWK Command

I am parsing file for the fields using awk command, first i check 26th field for two characters using substr function if it matches then using for loop on array i search 184th field for 4 chars if it matches then i print the required fields but on execution i get the error, please help...... (5 Replies)
Discussion started by: siramitsharma
5 Replies

6. Linux

awk filter & Auto gen Mail

hi experts 2012-01-30 10:30:01:812 "y" "NA" "30/01/2012 10:30:01:154 AM" 2012-01-30 10:33:46:342 "y" "NA" "30/01/2012 10:33:45:752 AM" 2012-01-30 10:41:11:148 "n" "200" "30/01/2012 10:41:10:558 AM" 2012-01-30 10:44:48:049 "y" "NA" ... (7 Replies)
Discussion started by: nith_anandan
7 Replies

7. UNIX for Dummies Questions & Answers

AIX: mail command & server

Hi, I have to change the mail server, but I could not find the file where it is written in. I use the following command: </> echo krneki | mail -v -s "New report" receiver@our.comp Server name ("skala") can be seen in a terminal output .... receiver@our.comp ... Connecting to... (0 Replies)
Discussion started by: frajer
0 Replies

8. Solaris

identify the mail server for mail command

Hi , I am new to unix , i am using the mail and mailx command to send the mail .How come i will know the my mail command using which server as mail box.. Please help me .. Thanks in advance (1 Reply)
Discussion started by: julirani
1 Replies

9. UNIX for Dummies Questions & Answers

Problem with xterm & tcsh & sourcing a script in a single command

Hi friends, I have a script that sets the env variable path based on different conditions. Now the new path variable setting should not done in the same terminal or same shell. Only a new terminal or new shell should have the new path env variable set. I am able to do this only as follows: >cd... (1 Reply)
Discussion started by: sowmya005
1 Replies
Login or Register to Ask a Question