How to grep a string and add to subject line of a mail?
I am running a mailx command as follows in Linux:
I am trying to parse the file "sla_local_sql_timings.out" for the word Elapsed Time: and get the time from that file stored in a variable and display that variable in the subject line of my email. Is this possible at all?
Contents of sql_timing.out looks as below:
All i am trying to do is take the values "00:10:00.10" and "00:15:00.10" and add it to the subject line.
So the Subject line of my mail should be: Elapsed Time: 00:10:00.10 00:15:00.10
Can someone guide me on how to get this done please? thank you
Moderator's Comments:
Please use CODE tags to mark sample code and input and output samples. I guessed at where the CODE tags should go on your sample input and probably guessed incorrectly about where empty lines are supposed to appear.
Last edited by Don Cragun; 08-03-2013 at 12:51 AM..
Reason: Add CODE tags
Thank you for giving me your time on this. I have worked on Regex commands before and have some knowledge. I am now trying to educate myself on your code works so I can further refine it.
This really is a pretty simple script, but if you aren't used to seeing all of the constiuent pieces combined together, it can be confusing. So, here is my script with line numbers added for discussion purposes. (This script will not work if the line numbers are included in the script.)
If you make this an executable script using the command:
(where script_name is the name you chose to contain the original script), line 1 tells the system the name of the program to be used to interpret the remaining lines in the file. So, no matter what shell you are using when you invoke this script, /bin/ksh will be used to run this script.
Line 2 sets a variable containing the name of your input file. (It assumes that RUNDIR has been set as an exported shell variable before you call this script. I made that asuumption because your 1st message in this thread used this variable without showing how it was set.)
Lines 3-9 set the variable Subject to the string "Elapsed Time:" followed by the output of a command substitution. Command substitutions are of the form $(comand). In this case the command to be run is:
The lines in blue in this script look for lines that contain the string "Elapsed:". For every line that is found meeting that criteria, the variable c is incremented (all variables that haven't been set otherwise, have an initial value of 0 or an empty string depending on context) and then writes a space character followed by the contents of the 2nd field on that line (which is the elapsed time value you want to include in the subject line).
After every line in the file has been procesed, the commands in green associated with the special pattern END will be executed. In this case, it will print a string followed by a newline character. The string will be an empty string if c is not 0; otherwise, it will be the string " None".
And, the $InputFile on line 9 at the end of the awk script is the name of the file to be processed.
The trailing newline character written by this awk script will be removed as a side effect of command substitution.
Then line 10 sends mail to ora_dbas with the subject set to the string contained in the variable Subject and the body of the message being the contents of the file named by the variable InputFile.
Hi,
I have a file which is an extract of jil codes of all autosys jobs in our server.
Sample jil code:
**************************
permission:gx,wx
date_conditions:yes
days_of_week:all
start_times:"05:00"
condition: notrunning(appDev#box#ProductLoad)... (1 Reply)
Dear All
I am having a text file which is having more than 200 lines.
EX:
001010122 12000 BIB 12000 11200 1200003
001010122 2000 AND 12000 11200 1200003
001010122 12000 KVB 12000 11200 1200003
In the above file i want to search for string KVB... (5 Replies)
I have mail:
cat /home/oracle/scripts/dbsizedaily.txt | mail -s "$TODAY: PROD DB Size" $RECIPIENTS
I like to get and put USED_GB and %USED of the very last row from /home/oracle/scripts/dbsizedaily.txt.
/home/oracle/scripts/dbsizedaily.txt has :
DATE TIME TOTAL_GB USED_GB ... (6 Replies)
Hello, I'm configuring sendmail on an AIX 7.1 server (bos.net.tcp.client 7.1.1.15).
I've gotten sendmail to send mail through our Novell GroupWise server, so that mail from a user on the server appears to come from their GroupWise account, and replies to the email would go to their GroupWise... (0 Replies)
Hi,
I have below script
PROJECT_NAME=UDL/UDL_Weekly
sub= echo ${PROJECT_NAME}|cut -d "/" -f2
cat pr.sh|mail -s "`hostname`: $sub failed" sonu.pal@xyz.com
While running the script I am receiving the subject line in mail as " podetlsapp01: failed' instead of " podetlsapp01: ... (1 Reply)
Hi,
I have two variables x and y.
i need to find a particular string in a file, a workflow name and then insert the values of x and y into the next lines of the workflow name.
basically it is like as below
wf_xxxxxx
$$a=
$$b=
$$c= figo
$$d=bentley
i need to grep the 'wf_xxxx' and then... (6 Replies)
Hello Everyone,
I just started scripting this week. I have no background in programming or scripting.
I'm working on a script to grep for a variable in a log file
Heres what the log file looks like. The x's are all random clutter
xxxxxxxxxxxxxxxxxxxxx START: xxxxxxxxxxxx... (7 Replies)
I know how to grep, copy and paste a string from a line. Now, what i want to do is to find a string and print a string from the line below it. To demonstrate:
Name 1: ABC Age: 3
Sex: Male
Name 2: DEF Age: 4
Sex: Male
Output:
3 Male
I know how to get "3". My biggest problem is to... (4 Replies)
Hi
Am fetching a weekly report pf data..once i fetched the data i need a sent report by mail.
In the subject of that mail i want to sent a message like..
SUBJECT :The report had been fetched from (01/12/08 to 07/12/08).
I need to send a report like this every week with that particular... (2 Replies)