linux: how to run a command in a given directory

I simply want to just run a command (actually its a shell script) from a given directory as a cron job. How can I run it so that it is set to a given directory without using cd.


Solution 1:

Your question makes little sense. Use cd. If you ask for the answer not to use cd because you've tried it and it didn't work, it's likely you didn't enter it correctly in the crontab.

The simplest way would be to write a small shell script that will cd and run your main task, then cron the script.

Solution 2:

Just specify the path to the script. No need for cd:

0 12 * * * /path/to/script args

If your script looks for files in ., then you will have to use cd:

0 12 * * * cd /some/dir && /path/to/script args