Operating System - HP-UX
1833696 Members
3679 Online
110062 Solutions
New Discussion

Re: script with symcli command not work in cron

 
Camel_1
Valued Contributor

script with symcli command not work in cron

Hi there,

I have a script with the following lines:

#!/usr/bin/ksh
SYMCLI_DB_FILE=/var/symapi/db/symapi_db.bin
/usr/symcli/bin/symmir -g bcv1 query > /tmp/bcv_list

The script works find if I submit in Unix promot, but it didn't work if I put the script in the cron. Any idea.

Thanks,

Simon
12 REPLIES 12
Michael Tully
Honored Contributor

Re: script with symcli command not work in cron

What is the exact entry your using in cron?
What are the permissions/ownership on the script?
Anyone for a Mutiny ?
Camel_1
Valued Contributor

Re: script with symcli command not work in cron

I put in the full path of the script, the script is owned by root:sys and has "rx-" permission to owner, group.
Con O'Kelly
Honored Contributor

Re: script with symcli command not work in cron

Hi Simon

Presumably you're running the script from root's cron?

Also check /var/adm/cron/log.
Is the cron job listed there? It should show a rc??

Cheers
Con
Camel_1
Valued Contributor

Re: script with symcli command not work in cron

the cron daemon is running, I can see the script was execute from cron log. The output file didn't generate, but when I run the script in Unix promph it works fine.
Con O'Kelly
Honored Contributor

Re: script with symcli command not work in cron

Try exporting the SYMCLI_DB_FILE variable in your script.
(ie export SYMCLI_DB_FILE)
I've had problems with cron in the past when I didn't export the variable.

Cheers
Con
Michael Tully
Honored Contributor

Re: script with symcli command not work in cron

Besides adding 'export VARIABLE' as suggested by Con, you could also use an output log and add 'set -xv' to the script, to see exactly what it is doing. Remember cron is really stupid and does not like utilising any type of environment variables, so therefore all of them must be in the script.
Anyone for a Mutiny ?
twang
Honored Contributor

Re: script with symcli command not work in cron

Hi,

To debug the script problem, I always append output from every step of the script to a full path logfile, which permission could be 777.
Good luck.
twang
Jeromy Gregg
Advisor

Re: script with symcli command not work in cron

I thought of a couple of things that you might check...

In addition to checking permissions, and exporting your variables, you should make sure that the script is running under root's crontab. Also, try sourcing the user's environmental files in the script. That would make your script look something like this:

#!/usr/bin/ksh
. /my/user's/home/directory/.profile
. /my/user's/home/directory/.kshrc
export SYMCLI_DB_FILE=/var/symapi/db/symapi_db.bin

/usr/symcli/bin/symmir -g bcv1 query > /tmp/bcv_list
Cheryl Griffin
Honored Contributor

Re: script with symcli command not work in cron

This is the key:
>>The script works find if I submit in Unix promot, but it didn't work if I put the script in the cron. Any idea.>>

When you login, your .profile is sourced which sets up your environment variables.

Cron runs in a pseudo environment. So any environment variables needed would have to be set in the script.

set -x will help you find what is not being set.
"Downtime is a Crime."
Michael Schulte zur Sur
Honored Contributor

Re: script with symcli command not work in cron

Hi Simon,

since you do not redirect errors, you might find error ouput in mail.
If the command ran, it should have created /tmp/bcv_list no matter what other errors come from the programme.
Can you post the crontab entry?

use:
#!/usr/bin/ksh
export SYMCLI_DB_FILE=/var/symapi/db/symapi_db.bin
/usr/symcli/bin/symmir -g bcv1 query > /tmp/bcv_list 2>&1


greetings,

Michael
Camel_1
Valued Contributor

Re: script with symcli command not work in cron

thanks everyone, it works now.
Michael Schulte zur Sur
Honored Contributor

Re: script with symcli command not work in cron

Hi Simon,

thanks for the points. Would you enlighten us as to the cause of the problem and the solution?

thanks,

Michael