The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-15-2008
ranga27 ranga27 is offline
Registered User
  
 

Join Date: May 2006
Posts: 63
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!!!
  #2 (permalink)  
Old 02-15-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Question All one one line?

Is the text in the file

pub 5858D/58585255EF 2007-10-02 unicorn01516008 <uniccrn@fund.com>
sub 452659g/97974545df 2007-10-02 [expires: 2008-06-22]

all on one line? Thus, one line per license key entry?

and are these entries all within some file called xxx.txt?
  #3 (permalink)  
Old 02-15-2008
ranga27 ranga27 is offline
Registered User
  
 

Join Date: May 2006
Posts: 63
They are in seperate lines

all the informations are loaded into xxx.txt

Thanks!!
  #4 (permalink)  
Old 02-15-2008
ranga27 ranga27 is offline
Registered User
  
 

Join Date: May 2006
Posts: 63
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
  #5 (permalink)  
Old 02-15-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool Try this one...

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
Make sure to adjust the admin variable at the top. Seemed to work with a file which I used as a sample:

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]
  #6 (permalink)  
Old 02-15-2008
ranga27 ranga27 is offline
Registered User
  
 

Join Date: May 2006
Posts: 63
Quote:
Originally Posted by joeyg View Post
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
Make sure to adjust the admin variable at the top. Seemed to work with a file which I used as a sample:

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]
If my output file is having double line will it work , also if the length varies in my keys , this will work ??

Thanks Again!!
  #7 (permalink)  
Old 02-15-2008
ranga27 ranga27 is offline
Registered User
  
 

Join Date: May 2006
Posts: 63
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!!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0