Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm still trying to learn a little more about bash scripting and start-up / reboot, I have read about crontab @reboot and also just looking at other options but I just wondered if someone could maybe point me in the right direction before I find out there are limits on the method I am trying so on...

Here is what I am trying to accomplish:

I have 2 users that need to run processes on reboot / start-up:

User1: 5 Processes all run with standard privileges (No problems here)

User2: 2 Escalated commands (sudo) and 5 processes standard privileges to be run but only once mysql and the above processes are active.

I only have ssh access to the server so this is why I have opted from the info I have been reading to try the bash/cron method.

I have tested sudo command works with a bash script and seems to be good, all the accounts use keys rather than passwords so I do not get prompted to confirm the password, I've yet to test this on a reboot but will do very soon.

The main problem is checking if the 5 processes run by user1 have loaded before letting user2 start its work, with two separate bash scripts is it possible to create a wait or loop to check for running process names before continuing on?

Thanks

share|improve this question

2 Answers 2

Yes you can. Here is an example this script sleeps for 30 seconds you can also use 1m to sleep for 1 Minute. You could also try adding /root/myscript to /etc/rc.local however I don't know if that work with the execution time you need.

#!/bin/bash
sleep 30
/root/myscript

share|improve this answer
    
I had wondered about this but wasn't sure if it was the best route as it does not confirm the process is running before continuing on with the next set of commands. Thanks though will keep this in mind –  user1312469 Feb 25 at 15:16
    
This could also work but there are two things that may not make it ideal. You never know for sure if your processes are running correctly (error, slow, etc), also, be default you minimum wait time is 30 seconds. If you can guarantee the successful run of the processes, and don't mind a set wait time, this is very simple sufficient. –  Mr.Lee Feb 25 at 15:16

I'm not completely sure if this is what you are looking for, but I believe .profile is run on boot for the individual user.

I hope this helps for half your problem, though if you are logging the user simultaneously , I don't believe it will work sequentially.

Ubuntu .profile

A way I use to check processes is with python scripts. I don't know if its possible to do loose checks in bash but I know in python you can try using Popen to run the terminal command

ps aux | grep the-process

as such

p = subprocess.Popen(('ps', 'aux'), stdout=subprocess.PIPE)
g = subprocess.Popen(("grep", "the-process"), stdin=p.stdout, stdout=subprocess.PIPE)

And it will return you a list of the running processes with that name. Run a check and then you can have it loop until it becomes true.

Hope this also helps.

share|improve this answer
    
Thanks, I have a read :) –  user1312469 Feb 25 at 15:13
    
Just seen your edit: Going to have a look now see if I can get something running. Thanks again –  user1312469 Feb 25 at 15:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.