Help with Email Status shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Email Status shell script
# 8  
Old 01-23-2011
I suspect you are going to find a lot more of these so probably best to have a replace_list file.

Create a replace_list file for yourself with 3 ; separated fields
  1. Search string
  2. New status
  3. New error string
If 1. is found in your error string the string is replaced with 3. also if 2. is non-blank then status is replaced with 2.

For you requirements so far you need this replace_list:
Code:
abuse;;Error - for abuse
not exist;email;account that you tried to reach does not
timeout;;timeout
Greylisting;;Greylisting
delivery temporarily suspended;;delivery temporarily suspended
refused to talk;;host refused to talk to me:
CA Gateway Security;;Rejected by CA Gateway Security

New script to load replace list and output your required strings:
Code:
awk '
   NR == FNR { R[i++]=$0; next }
   /to=/&&/, status=.* \(/ {
   status="status=deferred";
   toemail=$0;
   errorstr=$0;
   gsub(".* to=<", "", toemail);
   gsub(">.*", "", toemail);
   gsub(".*, status=[^ ]* \\(", "", errorstr);
   gsub("\\)$", "", errorstr);
   for (i in R) {
       split(R[i], F, ";");
           if(index(errorstr, F[1])) {
               errorstr=F[3];
               if (F[2]!="") status=F[2];
           }
   }
   print toemail, status, errorstr
} ' replace_list mail.log

# 9  
Old 01-24-2011
Thanks for excellent help Chubler_XL

i am getting an error while i run this script

[dispatc 05:04 AM| ~]# sh test.sh
wk: not found


i have created a new file replace_list
touch replace_list
vi replace_list
abuse;;Error - for abuse
not exist;email;account that you tried to reach does not
timeout;;timeout
Greylisting;;Greylisting
delivery temporarily suspended;;delivery temporarily suspended
refused to talk;;host refused to talk to me:
CA Gateway Security;;Rejected by CA Gateway Security


paste these lines and after that i modify the log location to /var/log/maillog from mail.log then i am getting this error i hav no idea that what is wrong here

---------- Post updated at 05:20 AM ---------- Previous update was at 05:08 AM ----------

Thanks a lot the script was working it was my mistake copy and paste i used wk insted of awk i am sorry and thanks for your great help

---------- Post updated at 05:23 AM ---------- Previous update was at 05:20 AM ----------

Hello Chubler_XL

I would like to exclude the line similer to this root@ how can do this please help me

root@localhost status=deferred delivered to file: /dev/null

---------- Post updated at 08:34 AM ---------- Previous update was at 05:23 AM ----------

please help me i would like to exclude the line with mail to root
# 10  
Old 01-25-2011
New line to exclude root@ emails added below (in blue)

Code:
awk '
   NR == FNR { R[i++]=$0; next }
   /to=<root@localhost/ { next }
   /to=/&&/, status=.* \(/ {
   toemail=$0;
   status=$0;
   errorstr=$0;
   gsub(".* to=<", "", toemail);
   gsub(">.*", "", toemail);
   status="status=deferred";
   gsub(".*, status=[^ ]* \\(", "", errorstr);
   gsub("\\)$", "", errorstr);
   for (i in R) {
       split(R[i], F, ";");
           if(index(errorstr, F[1])) {
               errorstr=F[3];
               if (F[2]!="") status=F[2];
           }
   }
   print toemail, status, errorstr
} ' replace_list /var/log/maillog

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automation script for email alert when a job get complete with status successful.

Guyz, Please let me know about script which is to be sending an automatic email to particular mail id's when a monotoring job get complete with status successful. (1 Reply)
Discussion started by: Rehan Ahmad
1 Replies

2. Shell Programming and Scripting

Shell script has to run until the status value is updated

Hi All, Need some help like how to exit from the script after updating the column in data base. db2 connect to DB STATUS=$(db2 "SELECT STATUS FROM XYZ ) echo $STATUS Initially the status value will be '4' or 'NOT YET RUN'. The Shell script has to run until the status value is updated... (7 Replies)
Discussion started by: sumanmca2006
7 Replies

3. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

4. Shell Programming and Scripting

Help....script check status if see something then send email

autorep -m bogus Machine Name Max Load Current Load Factor O/S Status ___________ ________ ___________ ______ ________ ______ bogus --- --- 1.00 Sys Agent Online Status ______ Online Offline Missing Unqualified The "Status" always "Online". I like create a script execute run... (6 Replies)
Discussion started by: dotran
6 Replies

5. Shell Programming and Scripting

Script to email status

Hi, I have few processes in the server continuous run few jobs, each of the process will generate a log file which detailing when its jobs are completed. the logfile will has the name something like this, result1.log, result2.log, result3.log,.... result10.log, result11.log, result12.log.......... (8 Replies)
Discussion started by: khchong
8 Replies

6. Shell Programming and Scripting

how to suppress the status of fork in shell script

When command is executed by forking, the console displays the status of that command. I want to suppress it.. how to do it ? Example: var1=`date` & echo "hello world"; output: hello world + Done var1=`date` I want to suppress the second line "+ Done var1=`date`". I... (10 Replies)
Discussion started by: Arun_Linux
10 Replies

7. UNIX for Dummies Questions & Answers

Job Status for running shell script

Hello, I am running a shell script whose execution often takes several hours to complete. Is there way I can get some kind of status update as the job is running? Something as simple as the start and the current time stamp. Thanks, Gussi (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

8. Shell Programming and Scripting

return status after run the shell script

Hello, I wanted to delete all files which are placed 14 days back. Here is my below script. My script works very well and it deletes all files 14 days back. I wanted to display message incase if the delete script is not successful. The below script returns always successful. But the directory... (6 Replies)
Discussion started by: govindts
6 Replies

9. Shell Programming and Scripting

status bar in shell script or perl

How To Generate different different progress bar in shell script? like we install some software it show us progress, like we install RPM that also show us progress. Thanks, Bash (2 Replies)
Discussion started by: learnbash
2 Replies

10. Shell Programming and Scripting

check the status and send an email with status

Hi, We have a text file which has the following data. ISA~00~ ~00~ ~ZZ~VISTN ~ZZ~U1CAD ~051227~183 7~U~00200~000011258~0~P~< GS~FA~EE05J~U1CAD~051227~1831~000011258~X~002002 ST~997~0001 AK1~SH~247 AK2~856~2470001 AK5~A AK2~856~2470002 AK5~A... (3 Replies)
Discussion started by: isingh786
3 Replies
Login or Register to Ask a Question