24

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.

3
  • 1
    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.) Jan 13, 2013 at 23:48
  • 1
    There is really no "answer" to this questions....just many many preferences.
    – mdpc
    Jan 14, 2013 at 1:27
  • you might find some by default on /usr/sbin
    – tony gil
    Nov 4, 2014 at 19:04

1 Answer 1

24

Typically, I put mine in:

  • /usr/local/bin/ for scripts to be run by more than one normal user
  • /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.

7
  • "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.) Jan 13, 2013 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, 2013 at 23:53
  • 1
    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, 2013 at 23:54
  • 7
    @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, 2013 at 0:13
  • 1
    @juacala you'll need to give an absolute path, as cron's environment $PATH isnt the same as your user's.
    – Sirex
    Feb 6, 2018 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.