First off, I only just started learning how to use Linux yesterday so my abilities are very limited.

I am essentially creating a script that I can run everytime I turn on my VPS and the script then turns on all the servers. However due to my lack of knowledge I have ran into some difficulties as once the script gets to turning the servers on it doesn't change the directories, leaving it as the default directory.

I am not sure if I am doing it right at all, so if you find a mistake in the script it would be great if you could correct me - or if you have a more efficient way of doing something.

service mysqld start
sudo service httpd restart
sudo service vsftpd restart
echo finished initialization
cd ~/server_1 & dos2unix start.sh & sh start.sh & 
cd ~/server_2 & dos2unix start.sh & sh start.sh & 
cd ~/bungee_1 & dos2unix start.sh & sh start.sh && 
echo finished
  • 1
    What will happen if you do cd ~/server_1 &? – muru Dec 23 '15 at 21:13
  • It will fork it and run it in the background in a different shell ? – Digisec Dec 23 '15 at 21:23

Did you mean to use && instead of & ?

| improve this answer | |
  • No I believe one & makes it run as a background process? – Josh Dec 23 '15 at 21:12
  • 1
    It will run it in the background and not wait for it. How can you guarantee that it is still in the same directory to run the dos2unix and then the start.sh ? NB: my question was more of a statement. – Digisec Dec 23 '15 at 21:13
  • Oh wait, sorry I changed some of them from & to && and I think that solved it! Thanks for the help. – Josh Dec 23 '15 at 21:14
  • @Josh the set -e command would be another way to check (everything) for errors and abort the script on any failure. – thrig Dec 23 '15 at 22:15

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.