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

crontab relative path question 1

Status
Not open for further replies.

keak

Programmer
Sep 12, 2005
247
CA
Say we have a shell script that refer to relative paths for files/directories:
for example:
Code:
#!/bin/sh
cp thisfile ../thatfile
cd mydir

These type of file works fine when we issue it from the command line, but when we register it as a crontab, it seems that the files/directories have to be referred to absolute path.

It is easy to change this script since its small, but what if we have a really large shell script and all of it is implemented with relative references. Is there another optino than to check every line and make it absolute?
 
In the crontab:
cd /path/to/dir && yourscript

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
crontab does not preserve your environment and so when your process is started it gets a fresh, clean and empty shell to work in.
"at" and "batch" on the other hand (from memory), do indeed preserve your shell environment.


Trojan.
 
PHV - i had no idea you could do that! Nice. Have a star on me.


Kind Regards
Duncan
 
wow thanks for the quick replies,
yes PHV's method was just what I was looking for.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top