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!

Using a crontab'ed script, can I change pwd to script path? 2

Status
Not open for further replies.

MCubitt

Programmer
Mar 14, 2002
1,081
GB
I have a script, for example: /tools/IT/batch/script1.unix

When I use crontab to run it:
* * * * * /tools/IT/batch/script1.unix

I would like it to assume the pwd (do a cd?) of the location of the script... effectively doing cd /tools/IT/batch/

However, the script COULD move so we would change crontab but would not want to change the script.

Can this be done? How!

Thanks








Applications Support
UK
 
Not tested, but you could try:

cd /tools/IT/batch ;/tools/IT/batch/script1.unix

Using the ; breaks the 'command' in two. Better to put the cd in the script itself, though, in my view.
 
In the script:

Code:
#!/bin/ksh

#change to the directory in which this script resides

cd `dirname $0`

#just to show it worked right

pwd

#rest of your code below here

This should let you move the script all you want without altering it.

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top