in my /etc/init.d/blabla script, which is the correct way to determine if the system is booting or the user root is runnig the script ?

I am thinking about * parent pid * euid * terminal... pts ?


On traditional init (not systemd), your script would have $0 as something like Sxxblabla when run by init, where xx are two digits.

When run by a user, there are usually a lot of environment variables set, like USER, HOME, and so on that are not set when running from init.

Note that in general, you want the effect of running the command in the shell and running the command at startup to be as identical as possible. Otherwise it may test fine from the command line but file when you boot.

  • mmh I will check the $0 idea – Massimo Aug 7 '18 at 20:55

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.