Sponsored Content
Top Forums Shell Programming and Scripting need help in finding a string and to send an email using shell script Post 302167871 by ranga27 on Friday 15th of February 2008 05:29:09 PM
Old 02-15-2008
Quote:
Originally Posted by joeyg
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!!
 

10 More Discussions You Might Find Interesting

1. Solaris

Shell script to send email alert for core dump

Friends, I am in search for a shell script that is capable of running as a cronjob and have to send out an email when ever there is a CORE DUMP. Please post the hints to achieve my goal. Thanks in advance. (1 Reply)
Discussion started by: rtatineni
1 Replies

2. Shell Programming and Scripting

How to write a shell script to send an email to an id

Hi all, I want to know how to send an email using shell script ..... I tried a command call mail but it did not work.. Please any one reply.. With example if you know thanks.. Madhu (4 Replies)
Discussion started by: madhumathikv
4 Replies

3. Shell Programming and Scripting

make un shell script to send email

Hi, Someone Knows how to obtein a chain from a unix file, but not all the line, for exemple, for this file ,obtein only 902111111 and to keep the value, this value will be used to make a mailx. NF=ALL, SUBJ= FROM: SN=CD, SE=TOPCALL, NA=, N=902111111, N=TCLFI TO: SE=FAX, NA=, C1=... (0 Replies)
Discussion started by: peybol
0 Replies

4. Shell Programming and Scripting

How to send email once a day at certain time in unix shell script

hi, i have to send an email once a day at ceratin time say 22. i have tried with date commad, but not working.:( HOUROFTHEDAY=`date +'%H'` if ; then mailx -s "Info" emailid@org.com < $ProcessStatisticsFile fi Please help me... (5 Replies)
Discussion started by: sreelu
5 Replies

5. Shell Programming and Scripting

How to send email through shell script

Hi All, I am new to the unix , i have to deliver one script very urgently I have to write a shell script where i have i want to send email to specific email id in this script i want FROM to be parameterized and stored in a variable TO to be parameterized and stored in a variable... (3 Replies)
Discussion started by: nileshbhawsar
3 Replies

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

7. Shell Programming and Scripting

Shell script to send an email from the txt file

Hi Friends, Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file. text file contains the no. of records like: giridhar 224285 847333 giridhar276@gmail.com ramana 84849 33884 venkata.ramana@gmail.com... (6 Replies)
Discussion started by: giridhar276
6 Replies

8. Shell Programming and Scripting

Help with shell script to send email once

Hi Guys, I have this script which will monitor oracle db process if up or down.And I want it to send email if it's down and the time it's back to online. However my script just keep on sending "Email Up" if the db is up or "Email Down" if the db is down.Is there any way to trap it so that it... (5 Replies)
Discussion started by: d3xt3r
5 Replies

9. Shell Programming and Scripting

how to send html email from shell script

This is my below script which is working fine as it send only plain text email. So My question is- How can I modify my below script to send this as an HTML formatted email? I want to show the text color of this expression `(echo "100*$TEST2/$TEST1" | bc -l)` as `RED` in an email and that can be... (3 Replies)
Discussion started by: raihan26
3 Replies

10. Shell Programming and Scripting

Need command to capture word from shell script and send email

Hello Experts, Greeting to all of you. I have a requirement, that we have a shell script status.sh that check the status of server and server status shows as status.sh Enterprise Server - Running Admin Server - Shutdown Requirement is like whenever the output shows shutdown it should... (2 Replies)
Discussion started by: aks_1902
2 Replies
TGT-ADMIN(8)						      TGT Configuration Tool						      TGT-ADMIN(8)

NAME
tgt-admin - Linux SCSI Target Configuration Tool. SYNOPSIS
tgt-admin -[OPTION]... DESCRIPTION
tgt-admin is a utility which allows a persistent configuration of targets and luns. It uses tgtadm commands to create, delete and show targets. OPTIONS
-e, --execute read /etc/tgt/targets.conf and execute tgtadm commands. if target already exists it will be deleted and a new instance will be created with the new parameters instead. -d, --delete delete all the targets -s, --show show all the targets -f, --force don't exit on tgtadm errors -p, --pretend only print tgtadm options -v, --verbose increase verbosity (no effect in "pretend" mode) -c, --conf <conf_file> specify an alternative configuration file instead of /etc/tgt/target.conf, which is the default. -h, --help display a list of available options and exits CONFIGURATION FILE SYNTAX
The defualt configuration file is: /etc/tgt/target.conf. It defines all the targets and their properties. The configuration file is in XML format and uses tags. Configuration file contains several target blocks, where each block contains tar- get's proerties such as storage devices, initator ACL and authorization information. You can include other config files using: include /etc/tgt/xen/*.conf. There are 2 types of storage devices: backing-store - defines a virtual device on the target. direct-store - defines a direct mapped device with the same properties as the physical device (such as VENDOR_ID , SERIAL_NUM, etc.) initiator-address - allows connections only from the specify IP address. defaults to ALL if no "initiator-address" is specified incominguser - define iscsi incoming authentication setting. if no "incominguser" is specified, it is not used. outgoinguser - define iscsi outgoing authentication setting. if no "outgoinguser" is specified, it is not used. example for a configuration file: <target iqn.2007-04.com.example:san.monitoring> backing-store /dev/san/monitoring # if no "incominguser" is specified, it is not used incominguser backup secretpass12 # defaults to ALL if no "initiator-address" is specified initiator-address 192.168.1.2 </target> <target iqn.2007-02.com.example:san.xen1> backing-store /dev/san/xen1-disk1 # LUN1 direct-store /dev/san/xen1-disk2 # LUN2 initiator-address 192.168.1.2 # Allowed IP initiator-address 192.168.5.6 # Allowed IP incominguser user1 secretpass12 incominguser user2 secretpass23 outgoinguser userA secretpassA </target> <target iqn.2007-02.com.example:san.xen2> backing-store /dev/san/xen2 </target> <target iqn.2007-06.com.example:san.vmware1> backing-store /dev/san/vmware1 </target> FILES
/etc/tgt/target.conf Configuration file for tgt-admin. SEE ALSO
tgtadm(8) REPORTING BUGS
Report bugs to <stgt-devel@lists.berlios.de> TGT Configuration Tool 2008-07-21 TGT-ADMIN(8)
All times are GMT -4. The time now is 01:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy