I just created a script file that I intend to run daily using Cron. Currently the only way that I can get this to run with Cron is if I place it in “/usr/bin”. I’d rather not keep it there but would rather keep it in my home directory.
What do I need to do to be able to have this script in my home and still run it from cron?
Hi
In your home directory is a bin directory, that is the normal place to
put them
Now cron doesn’t know about the environment, where files are located.
So either at the beginning of your cron job you specify your PATH
environment else use the full path to any application.
–
Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.0 x86 Kernel 2.6.25.18-0.1-default
up 15:00, 2 users, load average: 0.31, 0.12, 0.08
GPU GeForce 6600 TE/6200 TE - Driver Version: 177.80
Wow you’ve been helping me a lot here lately I don’t seem to have a “Bin” directory in my home, so I created one. I must have deleted in once before. I’m not sure if I understand the part of your reply about the Path. This is what I have, I just copied it from another script that I found on the net. Is this correct?
export PATH=/usr/local/bin:/usr/bin:/bin
If so, I tried to test the script by running it from the konsole and I get the message “no such file or directory”. It will only run from the konsole if i move into the “Bin” directory first. Is that normal?
About your original question: it matters who will run the script root or a normal uid (your’s e.g.). When it is run by root (via the crontab of root) I would put it in /root/bin/. When it is run by you (your crontab) I would put it the bin in your home directory (as malcolmlewis advised) this will be /home/<your-uid>/bin/.
In both cases I would specify the complete path to the script in the crontab entry. So in roots crontab something like:
55 23 * * * /root/bin/<your-script>
and in the case you run it in your crontab:
55 23 * * * /home/<your-uid>/bin/<your-script>
An alternative for running it daily as root would simply be to put your script in /etc/cron.daily/.
BTW the PATH you specify in your last post is of no use finding a script in /home/<your-uid>/bin/ because that directory is not mentioned in the PATH variable at all. And second: where do you plan to put that **export PATH=… **statement? Not in your script I hope because that only means that the script can find itself from inside itself!
Then, after you have solved your placement/cron problem, try to find some documentation about variables (as you use them in shell scripts) and what it means when they are exported to the environment. Also some knowledge about the function of the PATH variable (allready in the environment, so no neeed to export it) might be usefull.