Best folder to put scripts to be run by cron as various users
Hi everyone. I've read multiple things in online articles so figured i'd post my question here for clarification.
I'm running RHEL, but where is the "proper" place to store user created scripts, that will be executed by cron by various user accounts on the server? In my googling, it appears the most common places to dump your scripts into are /usr/local/bin or /usr/local/scripts (but it appears a scripts folder isn't created by default on a new install I did). Some articles also mentioning to check the paths for cron, but I'm not sure how to do that either :( |
It doesn't matter. It's entirely up to you since you'll be hard coding the location in the cron tab anyway.
|
Not necessory to put scripts in /usr/local/bin or /usr/local/scripts directories. You can create a simple direcotry in your home dir. and put all your scripts in that.
Code:
~$ mkdir /home/username/myscripts On the other hand, if you want to run those scripts without using their absolute path, simply add parant directory of those scripts in your PATH variable, as: Code:
~$ export PATH=$PATH:/home/username/myscripts |
Thanks for the quick replies guys.
but how do I see what paths are current in my PATH now for cron? I'd still put the whole path in for the scripts into the crontab, but just curious since that would save me some typing if /usr/local was already in there, then I could put them in bin or create scripts to put them in, and I think I could omit the full path (if I wanted to in theory) |
^ its probably a good idea to always use the full path when running something in cron since cron doesnt always create the same environment variables as a normal user.
you can try scheduling something like /bin/echo "cron path = $PATH" > /path/to/some/file to see if it prints its $PATH variable. |
ok, I will try that. I was going to put the full paths in anyway, but was just curious how to see what is actually in PATH anyway
|
Quote:
Code:
~$ crontab -e |
Yeah, that's what I planned on doing, was more just curious about what PATH was set to.
|
This is what I get.
Code:
echo "cron path=$PATH" > pth && cat pth I have also used /opt/scripts in the past. But I do not know if there are reasons to not to do this. |
Quote:
When done correctly, you should get something like: Code:
cron path = /usr/bin:/bin |
an other option is to add your PATH= to the start of your crontab.
Code:
[ray@centos ~]$ echo $PATH Code:
PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ray/bin Code:
* * * * * foo.sh for me if it is a universal script (something that anyone on the system should be able to run, then Ill just place the script in /usr/bin and set visudo permissions for that specific script. the user can just execute foo.sh or what ever its called without the full path. |
If its definitely personal scripts, then keep them in the user's dirs.
If its a generic script that affects others, then probably /usr/local/bin or /opt/scripts. If a cron job for a group/project, use the projects bin dir if it has one. |
Thanks to everyone for your replies.
|
All times are GMT -5. The time now is 04:14 PM. |