Re: su from cron (150 Views)
Reply
Frequent Advisor
P-Dicky
Posts: 71
Registered: ‎02-01-2005
Message 1 of 14 (150 Views)

su from cron

Hi
I'm trying this from root cron
50 * * * * "su - wmsusr -c /wms/app/zabbix/check_zabbix.sh"

Works fine if I
# su - wmsusr
]: /wms/app/zabbix/check_zabbix.sh
1
2
3
4
5
wmsusr@prodomni ksh[392]:

Here is the script
HOSTNAME=`whoami`
echo 1
value=`ps -fu $HOSTNAME |grep zabbix| grep -v grep| wc -l`
echo 2
if [ $value -eq 0 ]; then
echo 3
rm -f /wms/app/zabbix/agentd.pid
echo 4
/wms/app/zabbix/zabbix_agentd -c /wms/app/zabbix/zabbix_agentd.conf
echo 5
fi
exit 0;
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 14 (150 Views)

Re: su from cron

Hi:

What does the '/var/adm/cron/log' show; particularly the return code (rc=)?

Regards!

...JRF...
Please use plain text.
Frequent Advisor
P-Dicky
Posts: 71
Registered: ‎02-01-2005
Message 3 of 14 (150 Views)

Re: su from cron

I should mention if I run
# su - wmsusr -c /wms/app/zabbix/check_zabbix.sh
from root prompt I get this

1
2
logout
#
Please use plain text.
Respected Contributor
Wilfred Chau_1
Posts: 404
Registered: ‎12-13-2000
Message 4 of 14 (150 Views)

Re: su from cron

you are trying to check if zabbix agent is running as wmsusr, if not remove the pid and start zabbix agent.

your second output ran as root, did you stop the agent before running the script? If the agent is running, you will see only 1 and 2 right?
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 14 (150 Views)

Re: su from cron

Hi:

I believe Wilfred may have found the reason.

You really ought to change the *name* of the variable that holds the *user* id. Calling the variable "HOSTNAME" is rather misleading :-)

Regards!

...JRF...
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,849
Registered: ‎03-06-2006
Message 6 of 14 (150 Views)

Re: su from cron

>value=`ps -fu $HOSTNAME | grep zabbix| grep -v grep | wc -l`

You may want to list what $HOSTNAME and "ps -fu $HOSTNAME" shows so you can make sure what you are looking for.
Please use plain text.
Frequent Advisor
P-Dicky
Posts: 71
Registered: ‎02-01-2005
Message 7 of 14 (150 Views)

Re: su from cron

Hi All...

Hostname is a bad var name but I don't see how it causes the problem... The agent is not running when I'm running the script and from root

su - wmsusr -c /wms/app/zabbix/check_zabbix.sh

Results
~/.kshrc

1
2
logout

Any ideas? THANKS!
Please use plain text.
Frequent Advisor
P-Dicky
Posts: 71
Registered: ‎02-01-2005
Message 8 of 14 (150 Views)

Re: su from cron

Just to confirm again... If I su to wmsusr and then run all is fine... Just when I'm calling from roots cron and trying to su to that user do I have an issue.
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 9 of 14 (150 Views)

Re: su from cron

HI (again):

> If I su to wmsusr and then run all is fine... Just when I'm calling from roots cron and trying to su to that user do I have an issue.

Why do you 'cron' this as 'root' if you then switch to the 'wmsusr'?

What happens if you 'cron' this task as the 'wmsuer' ?

Regards!

...JRF...
Please use plain text.
Frequent Advisor
P-Dicky
Posts: 71
Registered: ‎02-01-2005
Message 10 of 14 (150 Views)

Re: su from cron

Right now only root user has cron and because of service guard they just want one crontab to maintain... Small IT group.
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 11 of 14 (150 Views)

Re: su from cron

Hi (again):

> Right now only root user has cron and because of service guard they just want one crontab to maintain... Small IT group.

Regardless, would you humor us and try running as a crontask of 'wmsusr' (without the need to 'su')?

> Hostname is a bad var name but I don't see how it causes the problem

Of course not. I merely was pointing out that when you ask someone to look at your code, it always helps to have used *meaningful* variable names. You wouldn't show me an orange and tell me that the apple you have is rotten, would you?

Regards!

...JRF...
Please use plain text.
Respected Contributor
Wilfred Chau_1
Posts: 404
Registered: ‎12-13-2000
Message 12 of 14 (150 Views)

Re: su from cron

what is the result, if you do not invoking a login shell? i.e.

50 * * * * "su wmsusr -c /wms/app/zabbix/check_zabbix.sh"
Please use plain text.
Frequent Advisor
P-Dicky
Posts: 71
Registered: ‎02-01-2005
Message 13 of 14 (150 Views)

Re: su from cron

Hi All... I just moved the su into the script and it is fine now...
echo 4
su - wmsusr -c "/wms/app/zabbix/zabbix_agentd -c /wms/app/zabbix/zabbix_agentd.conf"
echo 5

Please use plain text.
Frequent Advisor
P-Dicky
Posts: 71
Registered: ‎02-01-2005
Message 14 of 14 (150 Views)

Re: su from cron

See above, opps.
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation