2

I have a bunch of maintenance scripts that are typically only run by cron or root. I had been putting them in /usr/local/sbin but honestly, I don't want them in the path. Normal users can't (and don't want to) run them and even root doesn't need them in the path. There are several other options, but I'm not sure which is best.

Considerations:

  • /root/maintenance - Reservation is that not all maintenance scripts run as root.
  • /opt/maintenance - Guess it is an optional package.
  • /usr/local/maintenance - If placing sub-directories in /usr/local isn't unorthodox.
  • /etc/maintenance - Doesn't seem like a configuration, but there are other scripts are in /etc.

While I understand I can put the maintenance scripts wherever I like, I'd prefer to place them in standard location. If there isn't one, a sensible location will do.

A. Que
  • 633

2 Answers2

2

I've used directories under /usr/local for a good number of years. Possibly from as far back as SVR3 but it might have been BSDI.

In this case, where there are a number of scripts grouped together as maintentance related tasks, I'd consider /usr/local/maintenance/bin with related configuration files in /usr/local/maintenance/etc. In my case such directories would typically be accessible by all users - not just root - but again that would be down to specific requirements.

Formalised in FHS 3.0 section 4.9.1, and then broken by me with section 4.9.2.

I've noticed that some people quite like the similar approach using /opt/{whatever}/bin. No significant difference as far as I can see.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • Yes, I do see that in section 4.9.2 it states "No other directories, except those listed below, may be in /usr/local after first installing a FHS-compliant system." While I like the /usr/local/maintenance/bin path better, it does sound like /opt/maintenance/bin is FHS compliant. Thank you. – A. Que Feb 23 '22 at 17:04
  • @A.Que it's your system – Chris Davies Feb 23 '22 at 17:09
-1

The following look to be quite common:

/root/bin

/root/.local/bin

though these might be more convention than anything else.

JdeHaan
  • 934
  • Are they? Have you seen this sort of scheme outside Ubuntu? As far as I know (but I may very well be wrong) the ~/bin thing is an Ubuntu convention. – terdon Feb 23 '22 at 15:31
  • Could be, but better stolen than badly create your own stuff. If it's Ubuntu, it might be Debian... See https://unix.stackexchange.com/q/316765/44864 for more. – JdeHaan Feb 23 '22 at 15:34
  • That is about ~/.local/bin not ~/bin. And putting scripts (i.e. non-binary files) in bin directories seems a little odd. Not very, mind you, just a little. Anyway, I was just wondering about your claim that these are common since I do not believe they are. Not my downvote, by the way for what it's worth. – terdon Feb 23 '22 at 16:04
  • /usr/local/bin contains a lot of scripts on a lot of systems ;-) – JdeHaan Feb 23 '22 at 16:11
  • My only concern with this set option is that not all maintenance cron jobs run as root. They might be launched by root, but run as some less privileged user. Could you provide a reference for this convention? – A. Que Feb 23 '22 at 16:13
  • That's it: a convention, a habit. No hard government backed law. – JdeHaan Feb 23 '22 at 16:15
  • @A.Que frankly I don't think it is a convention at all but instead a choice made by either just one or a small group of specifically Linux systems. It certainly isn't a broad, *nix convention and not even particularly common in the Linux world. – terdon Feb 23 '22 at 16:23
  • @terdon One CentOS 7 server I have has over 800 shell scripts in /usr/bin. Debian isn't much better. Scripts include GNU utilities so they might be somewhat ubiquitous. /bin/true was a shell script on SunOS 4.1.3 as an older example. – doneal24 Feb 23 '22 at 17:06
  • @doneal24 yes, hence the "Not very, mind you, just a little". Nothing wrong with putting scripts in bin directories, just slightly surprising to create a non-standard location for non-binary files and call that bin. But only slightly. – terdon Feb 23 '22 at 17:09
  • @terdon Yes, but /usr/local/exe/ looks odd on a *ix system. – doneal24 Feb 23 '22 at 17:11