1752796 Members
5902 Online
108789 Solutions
New Discussion юеВ

su from cron

 
P-Dicky
Frequent Advisor

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;
13 REPLIES 13
James R. Ferguson
Acclaimed Contributor

Re: su from cron

Hi:

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

Regards!

...JRF...
P-Dicky
Frequent Advisor

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
#
Wilfred Chau_1
Respected Contributor

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?
James R. Ferguson
Acclaimed Contributor

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...
Dennis Handly
Acclaimed Contributor

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.
P-Dicky
Frequent Advisor

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!
P-Dicky
Frequent Advisor

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.
James R. Ferguson
Acclaimed Contributor

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...
P-Dicky
Frequent Advisor

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.