|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Grep the last line and put on mail subject
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 : HTML Code:
DATE TIME TOTAL_GB USED_GB %USED ...... 03/05/2013 21:13 PM 3151.24316 2329.82947 73.9336619 03/05/2013 21:17 PM 3151.24316 2330.17322 73.9445703 "DATE: 03/06/13 - PROD DB Size: 2,330.17 GB - %USED:73.94" Please advise. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
grep matches regular expressions, it doesn't understand concepts like the 'last line'. awk does however. I'd try this: Code:
awk '{ L=$0 } END { $0=L ; print "DATE: "$1,"PROD DB SIZE: "$5,"%USED:"$6 }' OFS=" - " /home/oracle/scripts/dbsizedaily.txt |
mail -s "$TODAY: PROD DB Size" $RECIPIENTS |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
OR use
tail and
cut to get those field values: Code:
USED_DB=$(tail -1 /home/oracle/scripts/dbsizedaily.txt | cut -d' ' -f5) USED_PC=$(tail -1 /home/oracle/scripts/dbsizedaily.txt | cut -d' ' -f6) cat /home/oracle/scripts/dbsizedaily.txt | mail -s "$TODAY: PROD DB Size: $USED_DB - %USED: $USED_PC" |
|
#4
|
|||
|
|||
|
Quote:
|
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
You can use
printf to format the number to 2 decimal places and include thousand separators: Code:
USED_DB=$( printf "%'.2f" $USED_DB ) USED_PC=$( printf "%'.2f" $USED_PC ) ---------- Post updated at 17:16 ---------- Previous update was at 17:13 ---------- From printf manual: Code:
A block size specification preceded by `'' causes output sizes to be displayed with thousands separators. The `LC_NUMERIC' locale specifies the thousands separator and grouping. For example, in an American English locale, `--block-size="'1kB"' would cause a size of 1234000 bytes to be displayed as `1,234'. In the default C locale, there is no thousands separator so a leading `'' has no effect. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
A little experiment: Code:
awk 'END {print "\"DATE: "$1 "- PROD DB SIZE: ", $5+0, "- %USED:", $6-0, "\" ", REC |"mail -s"}' OFMT="%.2f" REC=$RECIPIENTS /home/oracle/scripts/dbsizedaily.txt |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
I would recommend to use tail, cut, and printf, as previously suggested.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Subject line missing while sending mail | sonu_pal | Shell Programming and Scripting | 1 | 06-13-2012 08:32 AM |
| how to put subject and body to mail from two files | sri1977 | Shell Programming and Scripting | 1 | 10-10-2011 09:40 AM |
| Perl - how to put to the next line if I have same pattern in one line | askari | Programming | 2 | 07-30-2011 01:30 PM |
| Remove line based on string and put new line with parameter | victor369 | Shell Programming and Scripting | 4 | 05-26-2011 09:49 AM |
| ls | grep (i dont know what to put here) | kevincobain2000 | Shell Programming and Scripting | 4 | 05-02-2011 11:56 PM |
|
|