Dan Lester

Well-Known Member
Dec 7, 2017
51
1
58
Austin TX
cPanel Access Level
Website Owner
Can someone explain to me why "cd" doesn't work in cron? I want to manipulate some files in a cron job, and I don't want to have to spell out the whole file address each time in my command line. I tried "PATH=workingdirectory; commandline" , and that doesn't seem to work either.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,235
2,422
363
cPanel Access Level
Root Administrator
Can you let us know specifically what you're trying to do? I'm not sure that cron has an idea of a current directory, as it just reads the path you provide, so knowing more about what you're trying to do might help us provide a workaround.
 

Dan Lester

Well-Known Member
Dec 7, 2017
51
1
58
Austin TX
cPanel Access Level
Website Owner
Well, I gave an example of what I'm trying to do. I want to put such a functionality in my cron command set. I want to schedule that functionality using cron.
 

Dan Lester

Well-Known Member
Dec 7, 2017
51
1
58
Austin TX
cPanel Access Level
Website Owner
Yes, my command line works perfectly outside of cron. I guess I could call a script, but we're talking about just a short command line. Odd that cron can't handle it.
Oops, good point. I meant /usr/bin/cd /home1/memyselfandi/mydirectory; cat x y > z doesn't work,
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,235
2,422
363
cPanel Access Level
Root Administrator
It looks like others have decided a script is the way to go for this:


This person changed the path of cron, but also confirmed cron doesn't handle "cd"

 

Dan Lester

Well-Known Member
Dec 7, 2017
51
1
58
Austin TX
cPanel Access Level
Website Owner
Points noted. Thank you. But you'd think all this would be spelled out in cron documentation.

Also interesting that PATH delimiter doesn't seem to work in the cron instruction. As in
PATH memyselfandi/mydirectory; cat x y > z