![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| shell script to send email with usage of space in the directory as description : | sakthifire | Shell Programming and Scripting | 3 | 04-18-2008 04:27 AM |
| help for shell script of finding shortest substring from given string by user | pankajd | Shell Programming and Scripting | 1 | 11-22-2007 12:27 PM |
| How to write a shell script to send an email to an id | madhumathikv | Shell Programming and Scripting | 4 | 10-23-2007 05:19 PM |
| Shell script to send email alert for core dump | rtatineni | SUN Solaris | 1 | 08-17-2006 02:33 PM |
| Shell to run query, encrypt and send email | cub | UNIX for Dummies Questions & Answers | 7 | 07-17-2002 04:10 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
need help in finding a string and to send an email using shell script
Hi All
i am writing a shell script which will search for a string "expires". once the search string is found it has to give the email address as the output and send an email to the person This is basically to find the encrypetd keys which are loaded in the unix server Below are sample keys not the true values: pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn@fund.com> sub 452659g/97974545df 2007-10-02 [expires: 2008-06-22] once i run the shell script it will execute the command gpg --list-keys and then search for the string and the output should be like this :: unicorn01516008 <uniccrn@fund.com> Expires on 2008-06-22 and this has to be emailed to some xxxx@xxxx.com can you please help me in giving me some sample code !!! Thanks a lot for your help!!! |
|
||||
|
pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn@fund.com>
sub 452659g/97974545df 2007-10-02 [expires: 2008-06-22] They are in seperate lines but if it searches for expires , it has to get this result (unicorn01516008 <uniccrn@fund.com>) as they are interrelated and all these informations are loaded in some output files xxx.txt |
|
|||||
|
Code:
#! /bin/bash
admin=me@mycompany.com
rm sample_key.mat 2>/dev/null
cat sample_key.txt | grep "expire" >sample_key.mat
while read zf
do
# echo $zf
fld1=$(echo $zf | cut -d" " -f4)
fld2=$(echo $zf | cut -d" " -f5)
fld3=$(echo $zf | cut -d" " -f9)
fld4=$(echo $zf | cut -d" " -f10)
subj="Expiring certificate"
mesg="$fld1 $fld2 $fld3 $fld4"
echo $mesg
echo "$mesg" | mailx -s "$subj" "$admin"
done < sample_key.mat
rm sample_key.mat 2>/dev/null
Code:
cat sample_key.txt pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn1@fund.com> sub 452659g/97974545df 2007-10-02 [expires: 2008-06-22] pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn2@fund.com> sub 452659g/97974545df 2007-10-02 [expires: 2008-07-22] pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn3@fund.com> sub 452659g/97974545df 2007-10-02 [expires: 2008-08-22] pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn4@fund.com> sub 452659g/97974545df 2007-10-02 pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn5@fund.com> sub 452659g/97974545df 2007-10-02 [expires: 2008-09-22] pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn6@fund.com> sub 452659g/97974545df 2007-10-02 pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn7@fund.com> sub 452659g/97974545df 2007-10-02 [expires: 2008-07-22] |
|
||||
|
Quote:
Thanks Again!! |
|
||||
|
Hi i tried with a sample file which has the list of keys
it gave me this output [expires: 2008-05-16] but the require output is unicorn01516008 <uniccrn1@fund.com> [expires: 2008-05-16] can you please correct me if i am doing anything wrong!! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|