Need to determine when linux/OSX is fully initialized [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
This question does not appear to be about programming within the scope defined in the help center.
Improve this question
I need a shell scripting way to determine when a remote linux/OSX has completed all /etc/init.d/* for what ever run levels I have chosen to run in.
since I know I can ssh into a virutal box on my net while it is still booting and run commands like /bin/true or /bin/ps that not everthing is in the state it needs to be.
essentially I need to
while [ ${INIT_STILL_RUNNING_ON_REMOTE_SYSTEN} ]
do
sleep 30
done
ssh remoteUser#remoteSystem:command

You could put a script in the run-level you are interested in that is the last thing to run and first thing to shut down that touches a file somewhere to indicate it has run.
For instance, if you made a script called S99finished and put it in the run-level folder it would run last at that run-level. A corresponding K00finished would run first when shutting down.
S99finished could look something like:
#!/bin/bash
touch ~/.init_finished
and K00finished could look something like:
#!/bin/bash
if [ -e ~/.init_finished ]; then
rm ~/.init_finished
fi
Then your startup script would poll until ~/.init_finished existed at which point it would go on it's merry way.
Note, the startup scripts run as root, so using the home directory tilde will put it in root's home. That's probably not ideal for what you're doing, but illustrates the point. It's just as easy to put it in /var/log or somewhere else common to poll from. Just remember it has to have read permissions for everybody wherever you stick it.

Related

Typing "cd.." in Linux terminal instead of "cd .." [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I come from MS-DOS background, where it is permitted to type cd.. (without the space between cd and ..) instead of cd ... The Linux terminal, however, finds cd.. objectionable.
Is there a way to make Linux terminal understand cd.. to mean cd ..?
I'm using Ubuntu.
And I am well aware that this is a rather silly problem, but I have cd.. committed to muscle memory (since early childhood, my brain has been wired that way) and I've been making that mistake at least twenty times every day, for several years now, ever since I started using Linux on a regular basis.
You could create an alias:
alias cd..="cd .."
If you add this to some file that's loaded whenever you log in (e.g., .bashrc if you're using bash), you'd get the effect of having this alias permanently available.

Using bash alias beyond one level (shell in shell) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I am looking to execute a alias on my terminal which will login to another shell and execute a command there.
For example,
sh = 'ssh admin#x.x.x.x'
shls = 'sh;ls' (also tried 'sh && ls')
In this scenario, when i give 'shls', i want to ssh to (pwd less entry enabled) x.x.x.x and then execute ls command over there. But the 'ls' part is not working.
I understand the shell changed and hence its no longer in parent shell's scope to trigger the ls, but just wondering if there is a way to push it to the logged in shell and execute there.
Infact, i wanted to use another alias which is avaiable in x.x.x.x in place of 'ls' but as a first step i want to atleast get this working.
Hope i could put it clearly, Thanks in advance for your help.
You can pass a command to ssh as an argument (after the various connection parameters):
alias shls='ssh admin#x.x.x.x ls'
BTW, I'd recommend against aliasing sh -- that's a commonly used command to run a shell script(*), and giving it a different meaning could cause confusion.
(* Though instead using the sh command, it's generally better to give the script a proper shebang line, and just enter its path.)

Run multiple commands in serial and make sure all commands run [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I want to run a series of unix commands, one after another. If any of these commands dies for whatever reason, subsequent commands should continue to run.
For instance, I have 3 commands called "setup", "long-running-job" and "teardown". If "long-running-job" finishes with whatever exit code, or dies unexpectedly, I want to make sure "teardown" gets run in any case.
Simply concatenating all commands with semicolons doesn't seem to work. I tried running touch test.txt; ping localhost; rm test.txt in macOS Terminal, closed the terminal tab while it's running, and found that the "test.text" didn't get removed.
If you want to make sure that even if your interactive window closes that your commands keep going and that all your command happen sequentially in the order you specify then use the method in this answer: https://unix.stackexchange.com/a/47231
Basically for the command line in your question
nohup sh -c 'touch test.txt; ping localhost; rm test.txt'
That means the hang up signal sent by closing the terminal is ignored.
Have you tried GNU parallel? Seems like the ideal tool for your needs.
$> parallel ::: setup long-running-job teardown
Parallel comes with tons of options to control halts, failures, jumps, retries, etc. See the manual and the tutorial for examples.

how to make supervisord unkillable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I finished installation of supervisord on my centos6, it works also well. But I found I could use command "kill" to kill supervisord itself. I think this is wrong, I suppose supervisord is not killable, otherwise it can not guarantee the safe of other services which controlled by it. So how can I make supervisord is not killable please.
This is by no means possible to be done in a correct way lets say, though there is something that you could try and i think it will work. In theory only root can kill all proccesses and all other can always be killed by their owner. What you could actually try is to create a user that has an unbreakable password and get root to start a procceess using su. (root won't be asked to provide a password but 'su' will change to that user)
su newacct ksh -c "/home/newacct/bin/the_process_to_start.ksh and its parameters"
su - newacct ksh -c "/home/newacct/bin/the_process_to_start.ksh and its parameters"
The dash says that you should execute the .profile of that user. It depends if you want to or not. (You don't have to execute a script, but I assumed you were likely to in this example.)
This way, nobody but root can kill this process because nobody can become that user.
You might want to google how to make an undecryptable password in /etc/shadow. It's easy actually.

What is the easiest way to create a script that runs on the next reboot only? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am looking to create a script that executes on the next reboot only (not each reboot).
For example, I have script test.sh:
cd /tmp
touch toto.txt
What is the easiest way to execute this script only on the next reboot?
By easiest I mean : minimal number of commands, and independent of the linux OS/Version (if possible).
After several searches I found I can use the init.d system. But I think that's not the best way, because my script must run only once.
Add something like
LOCKFILE=/var/lock/test_sh_done
if [ ! -f ${LOCKFILE} ]; then
touch ${LOCKFILE}
/path/to/test.sh
fi
to /etc/rc.local, and make sure that /etc/rc.local has the execute bit set. If you want to run it again at the next reboot, just delete the LOCKFILE.

Resources