Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd prefer to not keep it in my /home/myusername directory. Is there a best practice of where to store your shell scripts for cronjobs? At the root level?

I'm running ubuntu server 12.04 right now.

share|improve this question
Why don't you want to store it in your home directory? If they're for you personally, that's exactly where they should be -- probably in some well-named subdirectory. If they're for the system has a whole, perhaps they should be somewhere else. (The distinction may be vague if you're the only user.) – Keith Thompson Jan 13 '13 at 23:48
There is really no "answer" to this questions....just many many preferences. – mdpc Jan 14 '13 at 1:27
you might find some by default on /usr/sbin – tony gil Nov 4 '14 at 19:04
up vote 7 down vote accepted

typically, i put mine in /usr/local/bin/ (for scripts to be run by more than one normal user) and /usr/local/sbin/ (for scripts which are to be run as root). That way you separate the task that the script does, from cron which just automates launching it.

You'll need root to store files there, though.

share|improve this answer
"You'll need root to store files there, though." -- Not if you set the permissions right. I usually make /usr/local and its subdirectories group-writable, and add myself to the group (say, install). (Of course you'll need root to set the permissions in the first place.) – Keith Thompson Jan 13 '13 at 23:49
i'm the main user and have root privileges. i'd prefer to have no one else edit this so am leaning toward /usr/local. there's no standard /mycronjobs directory though that people usually create? – tarabyte Jan 13 '13 at 23:53
if you want noone else to be able to edit it. make it owned by root and set 500 or 700 permissions on it. - you could even do root:<your group> @ 550 or 770. for similar effect with you being able to edit without going root. imho it's cleaner to just sudo before editing the script though and have it owned by root. – Sirex Jan 13 '13 at 23:54
@terabyte, the standard directory is usually ~/bin which is then added to the $PATH. You asked for best practice, well it is saving your personal scripts in your home directory. It is neater and it makes it much easier to upgrade later. – terdon Jan 14 '13 at 0:13
if this is a personal script (noone else needs run it) terdon is correct. – Sirex Jan 14 '13 at 0:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .