1830901 Members
2129 Online
110017 Solutions
New Discussion

Script Heros

 
SOLVED
Go to solution
hpuxrox
Respected Contributor

Script Heros

Ok, I am looking to consolidate all of my email notifications coming from the system. First, I want to get the all of emails from one location. And, then, create an include function for korn shell to include in all of my scripts. Here is and example of what I have so far,
cut --------------->
for i in `cat /test/maillist | grep ADM | awk '{print $2}' `
do
mailx -s "`hostname` Make Recovery Status" $i < /tmp/make_tape_recovery.log
done
cut --------------->

I want to have emails going to diffent groups like ADM and USER. So, Ill I need to do is through it a permamiter on the group, subject and file that I want to send with the mail.

I know this is a lot, but I know you guys love this stuff.



7 REPLIES 7
KapilRaj
Honored Contributor

Re: Script Heros

Sorry .. Can't get on my head .. Are looking for some help ?.

Kaps
Nothing is impossible
Roberto Polli
Trusted Contributor

Re: Script Heros

Well, I'm afraid not to have understood :_(

what you got is:
a file full of mail

what you want is:
a mail, ok? But containg what?

Peace, R.

in the meanwhile, in 'for' cycle you can use
awk '/ADM/ {print $2}' /test/maillist
Marvin Strong
Honored Contributor

Re: Script Heros

I can understand that you want to create a function to do your emailing, I don't understand what you mean by

"get all of emails from one location"


As far as mailing groups goes why don't you just make aliases, instead of parsing files?

Then you can just email whatever group directly.
Steve Steel
Honored Contributor

Re: Script Heros

Hi

This is playing with fire since there are so many variables.

Why not change the scripts you have to mail themselves when a different default is needed

Cron will automatically send standard output and eventually standard error output to root or the owner of the crontab is you allow others to have cron.

See cron.allow

Output redirection to a specific mail address, disable/redirect the
standard output ,standard error and use a command in your script to send the
Crontab:

47 11 * * * /usr/local/bin/testit > /tmp/testit.out 2>&1

Output and error are redirected with the 2>&1 and disables the standard mail .

Cron Script:
# cat /usr/local/bin/testit
#!/usr/bin/ksh
echo "testit used at `date`"
mailx -s testit.mail name@machine < /tmp/testit.out
rm /tmp/testit.out

Thus user on machine received email which had the following :
"testit used at Tue Apr 20 15:51:25 METDST 2004"


Hope that will guide you

Steve Steel

If you want truly to understand something, try to change it. (Kurt Lewin)
Juergen Tappe
Valued Contributor
Solution

Re: Script Heros

Hi if you want to have a central admin location to redidect all your cron emails here a way how you could do it:

1. create a config file containing 2 columns
1st Name of the cronjob
2nd Email Adress (list)
i.e.
DEFAULT:user1@domain1
cronjob1:user1@domain1,user2@domain2
cronjob2:user3@domain3

2. modify all your cronjobs
2a.at the top of each job add
MY_NAME=$(basename $0)
exec > /tmp/$MY_NAME.$$.log
exec 2> &1
2b at the end of each job add
MAIL_ADDR=$(grep "^$MY_NAME:" /test/maillist | cut -d: -f2)
MAIL_ADDR=${MAIL_ADDR:-$(grep "^DEFAULT:" /test/maillist | cut -d: -f2)
cat /tmp/MY_NAME.$$.log | mailx -s "cronjob $MY_NAME on $(hostname)" $MAIL_ADDR
rm /tmp/MY_NAME.$$.log # if you like

hope this is what you wanted.....
regards
Juergen
Working together
Juergen Tappe
Valued Contributor

Re: Script Heros

sorry at the second MAIL_ADDR= line I missed a closed bracket :

MAIL_ADDR=${MAIL_ADDR:-$(grep "^DEFAULT:" /test/maillist | cut -d: -f2)}

this should be correct now...
Working together
Marvin Strong
Honored Contributor

Re: Script Heros

Another thing you could do, would be have all your systems, mail one system, and have a .forward for that systems user to whatever location you wanted.

node a root -> .forward to wherever
node b -> mails node a root
etc..