Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cron will not accept path!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Problem: Need to run a cron job as a particular user with all environment variables and paths set up.

example: 30 1 * * * /path/to/script.sh

What I tried:

All as specific_user crontab

30 1 * * * /home/.profile; /path/to/script.sh
-Does not work. If I echo env or path in the script.sh none of my vars are there. It looks like the first command gets spawned to a separate process.

30 1 * * * /path/to/script_that_calls_profile_then_runs_script.sh
-Does not work. If I echo env or path in the script.sh none of my vars are there. It looks like the first command gets spawned to a separate process.

Set /etc/default/cron PATH=/path_I_need/
30 1 * * * /path/to/script.sh
-Does not set path (stop and restarted CRON)

Set /etc/default/cron SUPATH=/path_I_need/
30 1 * * * /path/to/script.sh
-Does not set path (stop and restarted CRON)

As root crontab

30 1 * * * su - specific_user /path/to/script.sh
That works!

I would like to put the script in the user crontab not root.
 
Do you have an entry in cron.allow to allow you to run cron processes?
/usr/cron.d/cron.allow
 
Variables are kept to the session that runs .profile,
usually you have to place
. /home/.profile
in the beginning of your script.

Tony ... aka chgwhat
tony_b@technologist.com

When in doubt,,, Power out...
 
Hi

Whenever you execute .profile it spawns a subshell sets the variable and comes out then the subshell dies..doesn't serve any purpose.
Same thing happens if U call the .profile with in your script.so you have to do it as mentioned below.

At the begining of your script add this line

. /path/to/.profile

#note the "." and a space in the begining. it means run .profile on the current shell

Regards
Mohan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top