31

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.

tarabyte
  • 2,585

2 Answers2

29

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.

Sirex
  • 11,214
1

I follow Luke Smith's organization and put my cronjobs on ~/.local/bin/cron/. It seems sensible as ~/.local/bin stores all binaries and UNIX shell scrips of the local user.

Additionally, as @Sirex has suggested, you can use /usr/local/bin/ to store cronjobs globally, that is, for all users, and /usr/local/sbin/ for scripts which are to be run as root. Personally, for sake of organization, I would put them under the directory cron, to separate them from ordinary shell scrips or binaries.