First script

Hello everyone,
I do a script
script to read a log and find the value debug and send a mail to my inbox
This should happen every 5 minutes.
grep -i debug /app/bss/bea-bssalsbdomain/propertie/BSB_logconfig.properties

help me

thanks

You can store whatever is returned by grep command in a variable (say varNAME) then pass that variable to Mail::Sender as below

#!/usr/bin/perl

sub BEGIN {
        unshift (@INC,'/opt/dev/common/mds/perlLib');
}

use Mail::Sender;

$sender = new Mail::Sender {smtp => 'xxx.xxx.x.xx', from => 'abc@abc.com'};
$sender->MailMsg({to => 'abc@abc.com', subject => 'Your Subject', msg => $varNAME});
$sender->Close;

You need a MTA (Exim, Postfix, ...) installed on your machine to send mails.

grep -i debug /app/bss/bea-bssalsbdomain/propertie/BSB_logconfig.properties | mail -s 'Subject' mail@address.com

Put this command in an executable script and use cron to get it run every 5 minutes:

~$ crontab -e
(Edit the file as follow)
*/5 * * * * /complete/path/to/your/script.sh

thanks a lot.
but must send the mail only if DEBUG is.

I believe we must use if

tks

yes. I think you can use something like:

if [ varNAME -eq ""]

which means varNAME is null which in turn means grep has returned nothing, right?

#!/bin/sh

OUT=$(grep -i debug /app/bss/bea-bssalsbdomain/propertie/BSB_logconfig.properties)

# $? is the exit status of the last command. grep returns 0 if something was found
if [ $? -eq 0 ]; then
    mail -s 'Subject' mail@address.com << .
${OUT}
.
fi

exit 0
if [ $? -eq 0 ]

Nice! That's why I keep telling myself I need to practice. I hope I will get better some day :smiley:

Thanks to all.
I love you:):):slight_smile: