Crontab sourcing PATH?

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Crontab sourcing PATH?
# 1  
Old 11-12-2012
Linux Crontab sourcing PATH?

Hi,

Im trying to run script A which requires path /sbin.
I have a crontab entry to run script A every 10 minutes.
Script A is executed fine by cron, but because script A requires /sbin in its path it fails to run.
My situation is script A get overwritten from time to time so I can't modify script A to set path in there.

So my question is...
Is it possible to execute script A in cron by sourcing the path somehow without setting the path in the script.

I've tried exporting PATH and running the script but it seems like when the script executes, it is running with the default cron PATH.

Is there a cron default file which specifies this limited PATH? I would like to add the path there if it exists. /etc/crontab contains below

Code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

It already has /sbin specified, so then why does it only have /usr/bin:/bin in its path when executing?

I'm using RHEL 6.2.

Hope my question is clear.
Thanks.

Wilson.

Last edited by Corona688; 11-26-2012 at 11:32 AM..
# 2  
Old 11-12-2012
Okay then set the PATH in your crontab

Code:
0, 10,20,30,40,50  * * * *  export PATH=${PATH}:/sbin && /path/to/my/script

# 3  
Old 11-12-2012
Hi Jim,

I tried your suggestion and this is what I get. I have echo $PATH > tmp.file in the script A so I can check if the path has been sourced. It continues to print one with /sbin in its path which I think is being logged from export then once the script A executes it prints the PATH as being /usr/bin:/bin to the default again.

/usr/bin:/bin:/sbin
/usr/bin:/bin

Thanks.

Wilson.
# 4  
Old 11-23-2012
If the contents of the script change the PATH variable and you don't have any permanent control over the contents of the script you have two choices from what I can see:

1) Create symlinks in /usr/bin for the /usr/sbin executables the script needs. This can be a pain if there's a lot of them or if it's a long script and hard to guess what all it does, but it's a definite workaround to your issues with the script.

2) Explain to whoever is in charge of writing the script that it's broken. Ultimately there's only so much you can do if the script is breaking itself. Let them know that the change their script is making is causing it to have a bug on your platform and let them fix it however they need to. It's possible they wrote it for some other platform where all the executables it needs are either in /usr/bin or /bin.
# 5  
Old 11-26-2012
Hi thmnetwork,

I ended up asking the script owner to add the PATH. Thanks for the suggestions.

Wilson.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep script name with path from crontab

I need help to grep file name with path from crontab ex : 0 5 * * * /tmp/test.sh 2>/tmp/test.log output : /tmp/test.sh Please use code tags next time for your code and data. Thanks (6 Replies)
Discussion started by: jhonnyrip
6 Replies

2. Shell Programming and Scripting

Reading a crontab 3 * * 1,3,5 /path/of/script.sh

Hi! We are on AIX 6.1 TL6 I am an Admin for a Content Management application that is hosted on an AIX machine and i am supposed to come up with a cronjob that runs every monday at 03:00 am. The current schedule of that cron job is : 3 * * 1,3,5 /path/of/script.sh But i do not know... (5 Replies)
Discussion started by: atechcorp
5 Replies

3. Shell Programming and Scripting

Script working when run manually but not in crontab showing path not found

i have a script running using variable defined in .profile when i run that script manually its working but when i run the same script through cron its giving path not found I had defined path in .profile (3 Replies)
Discussion started by: raj_saini20
3 Replies

4. Shell Programming and Scripting

sourcing .profile for other users

Hi Team, Thank you for your time. i have a situation where the user IDs of the applicatio users have been locked down to Read only. Hence I am writing a script to invoke their old .profile every time they login. My problem is : when i run . $userpath/.profile from within the ksh script... (9 Replies)
Discussion started by: anitha111
9 Replies

5. Solaris

cannot add PATH to user crontab file

hi All, here is the problem: I'm not able to specify a PATH inside the user crontab file (/var/spool/cron/crontabs). The only syntax it accepts is the usual "* * * * * file" I'm not able to add PATH, or HOME, or MAILTO, or anything else. when I try to save the crontab, I have the error: ... (1 Reply)
Discussion started by: joe_x
1 Replies

6. Shell Programming and Scripting

Help with Nested Sourcing files.

Hi, I have a script #!/bin/ksh #reading parameters. . FileA Echo ...... ...... File A has all parameters. FileA: Infile=xyz.com outfile=abc.com #Userid file . FileB FileB: (2 Replies)
Discussion started by: pinnacle
2 Replies

7. UNIX for Dummies Questions & Answers

sourcing the .bashrc

Hello, I am quite new to Linux... I need to set some aliases and I can't get it to work. Can somebody tell me what's wrong? I modified the .bashrc file in my home directory. I added: alias pmv= '/home/vera/MGLTools-1.4.5/share/bin/pmv' saved it and ran source .bashrc The shell... (3 Replies)
Discussion started by: Nusy
3 Replies

8. Shell Programming and Scripting

Maintain full path of a script in a var when sourcing it from a different script

Hi All, I've searched through the forum for a solution to this problem, but I haven't found anything. I have 2 script files that are in different directories. My first script, let's call it "/one/two/a.sh" looks like this: #!/bin/sh IN_DIR=`dirname $0` CUR_DIR=`pwd` cd $IN_DIR... (4 Replies)
Discussion started by: mrbluegreen
4 Replies

9. UNIX for Dummies Questions & Answers

crontab and path

hi All, here the problem: I'm not able to specify a PATH inside the crontab file. The only syntax it accepts is the usual "* * * * * file" I'm not able to add PATH, or HOME, or MAILTO, or anything else. when I try to save the crontab, I have the error: "crontab: error on previous line;... (3 Replies)
Discussion started by: fuliggians
3 Replies

10. UNIX for Dummies Questions & Answers

arguments in sourcing file

Hello ! I want to make a script like that. #!/bin/csh -f setenv toto me setenv titi you setenv tata $1 in which tata is visible outside the script, after sourcing this script. It seems that you can only do source script and not source script arg How can I do that ? ... (4 Replies)
Discussion started by: Nathe
4 Replies
Login or Register to Ask a Question