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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bash Execution problem with the crontab 1

Status
Not open for further replies.

nicox59

Programmer
Jun 10, 2009
4
FR
Hi,
I have actually an execution problem with my crontab under AIX 5.3.

In my crontab, i have the current line :
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /tmp/test.sh > /tmp/test.txt 2>&1

My unix user is setup with ksh.

I have 3 shell files :

test.sh :
. /tmp/test2.sh

test2.sh :
echo "test2"
. test3.sh

test3.sh :
echo "test3"

The result file "test.txt" :
test2
/tmp/test.sh: test3.sh: cannot be found.

I can't modify test2.sh and test3.sh.

Have you an workaround for this problem because this example can be only launch with an command line.

Regards
Nicolas
 
Put a [tt]cd /tmp[/tt] (or whatever other directory that test3.sh is located in) in test.sh before you call test2.sh


HTH,

p5wizard
 
Does test2.sh change anything to the current working directory?


HTH,

p5wizard
 
No.
I had an line echo $PWD in test2.sh, i see : /tmp
But i have the same problem.
 
You said you can't modify test2.sh or test3.sh ???
Put you were able to put in an [tt]echo $PWD[/tt] in test2.sh ;-)

So, as this is apparently your testbed, can you put these lines in test2.sh:

[tt]echo $PWD
echo "pwd command yields $(pwd)"
ls test*sh
ls test3.sh[/tt]

and run again. Then show output please?


HTH,

p5wizard
 
add the path to test3.sh into your parent shell script with export PATH=$PATH:/tmp ...

i'm assuming it cant find test3 because its not in the path and dot may not be in your path either which means PWD wouldn't have any effect, yes?
 
Well, Nicolas is trying to run the scripts with the . (source) command, which says: read commands from this file test3.sh here.

The . command should find the file in the current dir...

Nicolas, you might want to put in a command [tt]ls -l test3.sh[/tt] also


HTH,

p5wizard
 
ahh yeah, well. have you verified the other two shell scripts are set executable?
 
testing this out real quick in bash anyways, it only worked once i explicity set the path. before that it was telling me that the file to be sourced was not found even though it was in the local directory.....
 
It works exactly as I would expect even from cron (if I cd /tmp inside the first script). I just tried it out on an Ubuntu VM.

Needs execute permission on first script and read permission on second and third. That's all.


HTH,

p5wizard
 
Result :
test2
/tmp
pwd command yields /tmp
test2.sh
test3.sh
test.sh
test3.sh
/tmp/test.sh[2]: test3.sh: introuvable.

Same problem. I have find only one solution.
Modify test2.sh :
echo "test2"
. ./test3.sh

Thanks
Nicolas


 
OK, exsnafu was right on the money: . needs to have either . or (in this case) /tmp in the PATH variable.

So if you are allowed to change this variable, just put in

[tt]PATH=${PATH}:.
cd /tmp[/tt]

in the calling script.

But /tmp is a strange place to be putting scripts anyway IMHO.


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top