1821544 Members
2179 Online
109633 Solutions
New Discussion юеВ

bizzare script problem

 
SOLVED
Go to solution
Kevin Wright
Honored Contributor

bizzare script problem

in roots .forward file I have
| /bin/notify
to send all emails through this script.
in the script notify I have this

awk '{print $0}' > /tmp/mailfile

grep -i critical /tmp/mailtmpfile > /dev/null
if [[ $? -eq 0 ]];then

echo $SNA `arraydsp -a $SNA |egrep '(Overall State of Array)' |awk -F= '{print $
2}'` > /tmp/STATE

SNA is the serial numbers for the arrays..the arraydsp statement either comes back READY, or WARNING..
when I run this script by sending an email with CRITICAL in the message, $SNA is printed in /tmp/STATE, but the arraydsp statement is NOT..HOWEVER, if I comment out the first awk statement and put critical into /tmp/mailtmpfile and run the script from the command line, it works, both the SN and READY are in /tmp/STATE.

Any ideas?
10 REPLIES 10
Joseph C. Denman
Honored Contributor

Re: bizzare script problem

Probably a PATH problem. Use the full path in your arraydsp command. I would bet that would fix it.

...jcd...
If I had only read the instructions first??
Kevin Wright
Honored Contributor

Re: bizzare script problem

No, it's not a path problem, arraydsp does not get evaluated with or without the full path. Is there something special about arraydsp that is keeping it from getting evaluated through the email?
Sridhar Bhaskarla
Honored Contributor

Re: bizzare script problem

Kevin,

Try some debugging like this

STATE=`arraydsp -a $SNA |egrep '(Overall State of Array)' |awk -F= '{print $2}'`

printf $STATE $SNA \n >> /tmp/state

-Sri




You may be disappointed if you fail, but you are doomed if you don't try
Kevin Wright
Honored Contributor

Re: bizzare script problem

I have tested that, it doesn't matter, arraydsp -a does NOT get evaluated through the email, but it does get evaluated if you run it from the command line only.
Steve Post
Trusted Contributor

Re: bizzare script problem

Do you know how the environment is set when this program is running? Is your environment different from when you are running it on the command line?
I had a cronjob that kept failing because it never used /etc/profile or $HOME/.profile.
Joseph C. Denman
Honored Contributor

Re: bizzare script problem

Hmmmm I don't know Kevin. Sounds fishy to me. I still think this is in the env department.

Try to enliminate certain vaibles

env > /tmp/test.dat
echo $SNA >> /tmp/test.dat
arr=`arraydsp -a realnumber`
echo $arr >> /tmp/test.dat

Also, the script may not be translating the $SNA in the ``. I would try it like ${SNA}


...jcd...
If I had only read the instructions first??
Kevin Wright
Honored Contributor

Re: bizzare script problem

This is the script
#!/usr/bin/ksh
export SNA=00000120AEFD
awk '{print $0}' > /tmp/mails
grep -i critical /tmp/mails
if [[ $? -eq 0 ]];then
arr=`/opt/hparray/bin/arraydsp -a 0000120AEFD`
env > /tmp/test.dat
echo $SNA >>/tmp/test.dat
echo $arr >>/tmp/test.dat
fi

this is /tmp/test.dat
_=/usr/bin/env
AGENT=sendmail
SNA=00000120AEFD
PWD=/
TZ=MST7MDT
00000120AEFD

With a blank space at the bottom. Why does it have the Serial # 00000120AEFD at the end too?
Joseph C. Denman
Honored Contributor

Re: bizzare script problem

Ya, arr is too long. The ssn at the end is the $SNA value. SNA= is the export you did. I still think it is the path. Use the complete path for arraydsk, egrep, and awk.


GOOD LUCK

...jcd...
If I had only read the instructions first??
Jordan Bean
Honored Contributor
Solution

Re: bizzare script problem

What is the setting of DefaultUser in sendmail.cf? (Typically 1:1). Sendmail will switch to this uid:gid for all insecure operations outside of itself. This means that all functions through ~root/.forward are done as the DefaultUser while ~joe/.forward is done as joe. Check the perms of arraydsp. Here they are 0544, so only root can run it.
Kevin Wright
Honored Contributor

Re: bizzare script problem

The problem has been fixed, thanks to all who replied..I wish I would have been to access this site recently, because if I would have been able to read your post Jordan, it would have saved me some time..
I set the script to setuid root, and it worked, so I realized that through the email, the script was not getting executed as root. I thought it would because it was root's .forward file executing the script. I still don't quite understand what sendmail definition of insecure operations means.