4

Is it possible to call a bash script from inside an init.d script in linux? I need to call it and also return results. Sorry, I'm not a sysadmin and I've never created an init.d script. Right now I'm looking at other init.d scripts i see on my box and trying to see how it works.

Happydevdays
  • 213
  • 3
  • 6
  • 1
    is your system using systemd? (these days more likely than not) if so, contemplate on something like this: https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux – Theophrastus Dec 27 '16 at 19:07
  • @Theophrastus cool. I am trying to create a custom service in fact. Thanks.. – Happydevdays Dec 27 '16 at 19:12
  • With systemd the procedure to create a custom service is different from create a simple sh script – elbarna Dec 27 '16 at 19:50

1 Answers1

-2

Call a script from a script? Is a non-sense,is like hear "i want to drive a car using a car,how to do?" What is a script? A script is a ascii text file which need a shell to be "interpreted" or running. It can contain commands,but also loop(while,until) and other constructs like if..else..fi or case..esac. If you mean "i want to run a script" you have two ways

bash /etc/init.d/"script I want to run"

or

/etc/init.d/"script I want to run"

WARNING!Running some scripts as root without know what script is can damage your system. Before running a script read it's contents with

less /etc/init.d/myscript
elbarna
  • 12,050
  • 22
  • 92
  • 170
  • The OP's question is reasonable. Scripts in `/etc/init.d` have particular conventions, and it is prudent to not want to treat them like any other shell script without more information. – user4556274 Dec 27 '16 at 19:06
  • Thank you... I think.? I guess it can sound like non-sense if you're familiar with openrc-run ... and bash. But like I said. I'm not. Hence the question. And re: the warning - I'm making the scripts that will be called...so I know exactly what it will do. – Happydevdays Dec 27 '16 at 19:08
  • Is your whole first paragraph, just a rant over the use of the word "run" vs "call"? – ctrl-alt-delor Jan 27 '21 at 20:37