Script to email status


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to email status
# 1  
Old 09-30-2013
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.......
I want to grep all the logfiles with the keyword "completed", the line of the "completed" keyword will also has the date/time info, this will shows me when was the jobs are completed, also I want to sort the output based on logfile name in order, e.g. result1.log, result2.log, result3.log, result4.log etc... and then send me an email.
Anyone help me to construct the script will great appreciate.
# 2  
Old 09-30-2013
Because your filenames don't readily sort in order (as result2.txt appears to come after result10.txt but should come before it) you'll need to either teach the sort command to understand your name or explicitly list them all in the right order.

Once you have that all in some variable (say $FILES for example), you just need to grep them and pipe the output into mail.

eg
Code:
for file in $FILES
do
  grep "completed" $file
done | mail -s 'All these things are completed!' me@myemailaddress.com

You could run grep on the list directly, but then you've got to suppress grep's default behaviour of listing the filename before each output line.
# 3  
Old 10-01-2013
Hi,
thanks for the coding.
I have below files in my server:
Code:
output1.log
output2.log
output3.log
output4.log
output5.log
output6.log
output7.log
output8.log
output9.log
output10.log
output11.log
output12.log

when I do ls -1 | sort it will comes out as below:
Code:
output1.log
output10.log
output11.log
output12.log
output2.log
output3.log
output4.log
output5.log
output6.log
output7.log
output8.log
output9.log

The output10.log, output11.log, output12.log are comes out after output1.log, how could I sort the logfiles in the order where output10.log, output11.log and output12.log etc are come out after output9.log?

Thanks

Last edited by Franklin52; 10-01-2013 at 08:26 AM.. Reason: Please use code tags
# 4  
Old 10-01-2013
I think you are talking about this sequence.

Code:
 ls -1v output*

# 5  
Old 10-01-2013
Hi,
I don't have the v option, ls -lv gave me error
any other alternative?
# 6  
Old 10-01-2013
Please tell me your detail about your operating system.
# 7  
Old 10-01-2013
Hi,
Im using hpux 11.31
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

Send Disk Space Usage Status via email

Hi Guys, Is there any way I can write a script that sends DISK SPACE USAGE STATUS via email once a week? Thanks, (5 Replies)
Discussion started by: g4v1n
5 Replies

3. Shell Programming and Scripting

Need output of script on screen and file with correct return status of the called script.

Hi, I am trying to capture logs of the script in the file as well as on the screen. I have used exec and tee command for this. While using exec command I am getting the correct output in the file but, script output is not getting displayed on the screen as it get executed. Below is my sample... (14 Replies)
Discussion started by: Prathmesh
14 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. 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

6. 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

7. Shell Programming and Scripting

Help with Email Status shell script

I have written a bash script to to sort the data from logs i need some help in printing the outputs , i dont have much ideas in bah scripting. Sample script ----------------------- #!/bin/bash a=`date | cut -d " " -f2,2,3` cat /var/log/maillog |grep "$a" |grep -E -e 'deferred|bounced'... (9 Replies)
Discussion started by: unimaxlin
9 Replies

8. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

9. 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

10. UNIX for Dummies Questions & Answers

awk to find the status and send an email

Hi, I have a datafile which has the following data and it can have much more records. The data set is as follows: ISA~00~ ~00~ ~ZZ~F159B ~ZZ~U1CAD ~051215~184 3~U~00200~000011432~0~P~< GS~FA~TC11A~U1CAD~051215~1843~000011432~X~002002 ST~997~0001... (6 Replies)
Discussion started by: isingh786
6 Replies
Login or Register to Ask a Question