keep mail command active inside a script on unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting keep mail command active inside a script on unix
# 1  
Old 10-19-2010
keep mail command active inside a script on unix

well, I have a script with this code inside:

Code:
nohup  /usr/sbin/auditstream | /usr/sbin/auditselect -m -e "event== USER_Create || event== USER_Remove || event== USER_Change || event== GROUP_Create || event== GROUP_Remove || event== GROUP_Change || event== PASSWORD_Change " | /usr/sbin/auditpr -h elrtRc -t2 -v | tee -a /var/syslog/auditalerts.log | mail -s "AUDITALERT: Alert on `hostname`" user@domain &

This code doesn't work, I want to keep audit alerts on a file and generate en email (only once) whenever an event is generated. I used nohup & becuase I need this code running all the time.

Any idea from you guys? :-)

NOTE: This runs on AIX6.1

Thanks
Regards
Israel.
# 2  
Old 10-19-2010
Does it surprise you?
How will mail know when to send?
# 3  
Old 10-19-2010
Hi vbe,

No, it's not a surprise.. but I want to to look for possibles ways to get mail running only when a new event are generated. I've tested several commands but no success.

Last edited by iga3725; 10-19-2010 at 01:57 PM..
# 4  
Old 10-19-2010
The new event would be noticeable by the timestamp of the log change...
# 5  
Old 10-19-2010
First, nohup should be to a wrapper script, so every process on the pipe is nohup.

Let's assume that mess only produces output when there is a problem. I folded it, just couldn't help myself, sorry! Smilie

A time stamp in the email subject might be good, too! The stuff sometimes stops for a beer before showing up, or causes a panic when misfiled back to the inbox.

Code:
while [ 1 ] # or crontab
do

zmsg=$(
/usr/sbin/auditstream |\
 /usr/sbin/auditselect -m -e "\
  event== USER_Create ||\
  event== USER_Remove ||\
  event== USER_Change ||\
  event== GROUP_Create ||\
  event== GROUP_Remove ||\
  event== GROUP_Change ||\
  event== PASSWORD_Change\
  " |\
 /usr/sbin/auditpr -h elrtRc -t2 -v
)

if [ "$zmsg" != "" ]
then
 echo "$zmsg"  | tee -a /var/syslog/auditalerts.log | mail -s "AUDITALERT: Alert on `hostname`" user@domain
fi

sleep 9

done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Simple loop to mail all active users.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Send a fortune to all active/logged in users 2. Relevant commands, code, scripts, algorithms: So I understand... (8 Replies)
Discussion started by: kjcraig77
8 Replies

2. Shell Programming and Scripting

If else condition inside for loop of awk command in UNIX shell scripting

Hi , Please excuse me for opening a new thread i am unable to find out the syntax error in my if else condition inside for loop in awk command , my actual aim is to print formatted html td tag when if condition (True) having string as "failed", could anyone please advise what is the right... (2 Replies)
Discussion started by: karthikram
2 Replies

3. Shell Programming and Scripting

passing arguments to unix command or script inside tclsh

hi everobody kindly consider the following in tclsh I understand that we can do the following %exec UnixCmd arg1 arg2 but if I assinged the arguments to a list insde tclsh how can I use them back i.e %set ArgList %exec UnixCmd %exec Unixcmd $list %exec all the... (1 Reply)
Discussion started by: Blue_shadow
1 Replies

4. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

5. Shell Programming and Scripting

Error while using sqlplus command inside 'if' condition in an unix shell script

Hi all, I am using the below given sqlplus command in my unix script to invoke a stored procedure which returns a value .It works fine. RET_CODE=$(/opt/oracle/product/10.2.0.4.CL/bin/sqlplus -S $USER/$PASSWD@$DB_NAME <<EOF EXEC MY_PKG.MY_SP (:COUNT); PRINT COUNT; commit; ... (6 Replies)
Discussion started by: Shri123
6 Replies

6. Shell Programming and Scripting

UNIX Script to query Active Directory: give cn (NT login name) and receive mail (Email address)

Hi folks I need to write UNIX script (with ldapsearch) to query Active Directory. Input is NT login name and output is Email address. Attached a screenshot of Sysinternals "AD Explorer". I need to do the same in CLI. http://i.imgur.com/4s6FB.png I am absolute LDAP/ldapsearch noob. (0 Replies)
Discussion started by: slashdotweenie
0 Replies

7. Shell Programming and Scripting

Running a unix script(which is calling another script inside that) in background

Hi all, I am having a script ScriptA which is calling a script ScriptB in the same server and copying files to second server and have to execute one script ScriptC in the second server. THis First script ScriptA is the main script and i have to execute this process continously. for Keeping... (2 Replies)
Discussion started by: rohithji
2 Replies

8. UNIX for Dummies Questions & Answers

UNIX command for checking active Fibre Channels

Can someone advise what the UNIX command for checking active Fibre Channels is? I have used lcdev and this gives me a nice list of cards available to our box. The particular Fibre Channel I'm interested in is fcs6. This is showing as Available...if that is the case does this also mean that it is... (1 Reply)
Discussion started by: DavoH
1 Replies

9. Shell Programming and Scripting

unix command inside oracle

i connect to oracle in shell script and i execute a procedure . i want to find the exit status of the execution command inside oracle .is there anyway i can use $? or any other command is there . (1 Reply)
Discussion started by: dineshr85
1 Replies
Login or Register to Ask a Question