Score:0

Is it possible to run a sh script system wide, on specific condition?

in flag

Im a student, and don't know ubuntu very good. But i have a task, one part of which is "Configure the Linux server to run start-sample.sh on every server restart". I probably completely wrong, but in previous steps I have been required to install openSSH server, so Im assume I need to somehow put my start-sample.sh into openSSH config, so it will launch at every restart. Or maybe i need use rc.local, Systemd or Cron Job? I been thinking that maybe there is some sort of conditions which could be put into Systemd? For example "If openSSH is launching - then - run the script". It seems like very petty task on Windows but on Linux Im at lost.

PonJar avatar
in flag
You seem to be confused about the word server. The Linux server is the computer you connect to with SSH. The openSSH server is a piece of software that provides the SSH service. I suggest you research systemd unit files. You can use one to start your script very easily
Score:0
it flag

You are not looking on correct method. You have to start services & daemons from system services management you have to start user lands applications from user profiles tools you have to start specific tools from init, initrd, or systemctl depending on each of your needs.

The content of you scripts depands of your real goals, for examples

  1. bash script can be good for general purpose activities
  2. ansible might be more pertinant on system-wide setup for many different tasks to do at once in a steps sequence, like post-install scripts
  3. terraform might be good too & better for installations of os's with specific setup
  4. etc..etc..

all that to explain, you do not have to think about the content until you have your exact need knowledge and chosen the better approach/method/tool(s).

and cron is not a good idea at all for a start at boot. even it can be used technically possible

initrd has its own logic & role cron has its own logic & role systemd also and so on...

do not use them for random actions. choose them from their real roles

So First :

  1. list you exact needs
  2. check the best start process for each
  3. make it
  4. deploy it

in that order

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.