1833821 Members
2591 Online
110063 Solutions
New Discussion

Re: Questinon Crontab

 
cron job
New Member

Questinon Crontab

I have a script that starts a command (for staring a process) from /usr/local/bin. It should only be started by users and not as root. Right now the Cron job(is starting as a root) but failing to open my shared object(library) in /usr/local/lib. I need suggestions in resolving this issue. Any help would be greatly appreciated.
10 REPLIES 10
spex
Honored Contributor

Re: Questinon Crontab

Hi,

# crontab -e

to edit 's crontab.

Make sure appears in /var/adm/cron/cron.allow.

PCS
A. Clay Stephenson
Acclaimed Contributor

Re: Questinon Crontab

First, I will assume that read and execute permissions have been set on the shared library. Your script needs to set and export SHLIB_PATH to include /usr/local/lib. Cron's environment is intentionally very sparse so your cron'ed script may need to augment PATH and set and export any other needed environment variables.
If it ain't broke, I can fix that.
cron job
New Member

Re: Questinon Crontab

Thanks for the reply. So you mean to say I should define the PATH, HOME directly in crontab file.
spex
Honored Contributor

Re: Questinon Crontab

Hi,

No. You need to set these environmental variables in the shell script you have cron'ed.

PCS
A. Clay Stephenson
Acclaimed Contributor

Re: Questinon Crontab

No cron doesn't source a user's .profile. Notice that I said you needed to set and export these things in your cron'ed script. That means that you do something like this directly in the script that is invoked by cron:

#!/usr/bin/sh

export PATH=${PATH}:/usr/local/bin
export SHLIB_PATH=/usr/local/lib:/usr/lib

...
...
# your commands start here
If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: Questinon Crontab

Shalom,

cron has no environment other than what you set.

If it works in the regular command environment and not in cron, you need to set up the necessary environment, PATH, SHLIB_PATH etc.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
cron job
New Member

Re: Questinon Crontab

When I add that to my "cron-ed" script, i am getting an error like
"
I tried this before with no success. Your suggestions are greatly welcome
cron job
New Member

Re: Questinon Crontab

Thanks all. I forgot to mention that my system is Solaris. I dont know, I guess either my Script or Cron had problems understanding
export PATH = ... and
export LD_LIBRARY_PATH = ...
I had do something like
PATH=$PATH/usr/local/bin and
LD_LIBRARY_PATH=/usr/local/lib.

I have another doubt with regards to Cron, Is it possible to run two scripts separated by comma something like
Cron - "* * * * * ;"

Once again thanks for the timely help.
Patrick Wallek
Honored Contributor

Re: Questinon Crontab

Well, since you didn't mention Solaris initially everyone thought you were on HP-UX since this is an HP-UX Forum.

Anway, with Solaris you may have to use CSH syntax in your script.

setenv PATH /usr/bin:/usr/local/bin/:whatever

setenv LD_LIBRARY_PATH /usr/lib:whatever

To your last question -- Yes you can run scripts in the fashion you mention with the script names separated by a semi-colon.
A. Clay Stephenson
Acclaimed Contributor

Re: Questinon Crontab

Now get a baseball bat and whack yourself 5 times --- hard for omitting those tiny, insignificant data -- Solaris and csh.

If you don't feel confident that you can whack yourself hard enough then find a colleague because serious adjustment is needed.
If it ain't broke, I can fix that.