Operating System - HP-UX
1820708 Members
2831 Online
109627 Solutions
New Discussion юеВ

How to find PATH in cron job command?

 
SOLVED
Go to solution
j773303
Super Advisor

How to find PATH in cron job command?

Is there any default PATH for cron job? for
example, I put the command into /usr/bin/test,
but in cron job, it's only write 'test', and
it's still can execute?
Hero
9 REPLIES 9
Michael Tully
Honored Contributor
Solution

Re: How to find PATH in cron job command?

Hi,

cron does not know anythig about paths. You either need to put an absolute path name in the cron file, or use a script with a path statement in it.

HTH
Michael
Anyone for a Mutiny ?
Steven E. Protter
Exalted Contributor

Re: How to find PATH in cron job command?

cron scripts and commands run without PATH, TERM or any other environment variables.

Therefore command lines must include the full path of very single command.

I get around this by either using full patth names or calling scripts(with full path of the script ex /usr/contrib/bin/rec.tape.ksh)

Inside the script I establish a minipath to all of the commands the script uses. It usually takes a few tries to debug the script, but it works.

Set the TERM variable if you are running an application or anything that requires that information.

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
Ravi_8
Honored Contributor

Re: How to find PATH in cron job command?

Hi,

while cron is executing, it wouldn't show the path, it will be executing the command/script in the specified path in the crontab file
never give up
Christian Gebhardt
Honored Contributor

Re: How to find PATH in cron job command?

Hi

cron has build in some PATH information:

Try this:

* * * * * echo $PATH >> /tmp/path.txt

and you will find something like this:
/usr/bin:/usr/sbin:.

All other PATH-Information you have ot set explicitly

Chris
john korterman
Honored Contributor

Re: How to find PATH in cron job command?

Hi,
some commands are built into the shell, e.g. test. It is the built-in command you execute when you write "test" in your cron job. It is of course not necesarily the same command as in /usr/bin/test.

regards,
John K.
it would be nice if you always got a second chance
Trond Haugen
Honored Contributor

Re: How to find PATH in cron job command?

'test' is a built in command in the shell so IT is the one that will be run. Generally I would reccomend against calling "your own" command test. If you do you will always have to type the full path.
It is good practise to set the PATH in all scripts you create that will be run from cron.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Yogeeraj_1
Honored Contributor

Re: How to find PATH in cron job command?

hi,

Test is a built-in.
===============================================================
NAME
test - condition evaluation command

SYNOPSIS
test expr
[ expr ]

DESCRIPTION
The test command evaluates the expression expr and, if its value is True, returns a zero (true) exit status; otherwise, a nonzero (false) exit status is returned.
...
===============================================================

K250: usr/bin>more test
#!/usr/bin/sh
# @(#) $Revision: 72.2 $

# This is the execable verison of test utility implemented
# using posix shell built-in test command.

test $@
exit $?

K250: usr/bin>


I would normally set my environment variable in the script itself as others have said above and of course don't forget to the change the script to executable using: chmod +x <scriptName>

Best Regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Jdamian
Respected Contributor

Re: How to find PATH in cron job command?

You can read the following paragraphs in online help crontab(1m):

cron supplies a default environment for every shell, defining:

HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh

Users who desire to have their .profile executed must explicitly do so
in the crontab entry or in a script called by the entry.
Bill Hassell
Honored Contributor

Re: How to find PATH in cron job command?

Use the set command in your cron job to show what your current environment contains. cron NEVER logs in like a normal user so nothing in /etc/profile or .profile is run. All cron jobs should set PATH explicitly (actually, all reliable scripts should do this) to avoid issues like this. And of course, specialized variables that may have been added to login profiles should also be coded into cron scripts.


Bill Hassell, sysadmin