0

As I'm sure you'll all tell very soon, I'm no expert when it comes to this sort of thing. However, when trying to look at results, I've not been able to come across anything quite like what I need - so I decided to ask here.

BACKGROUND: When I log into my server, I need to cd into a folder and run some commands based on one of the 3 things I want to do:

1) Stop the server 2) Start the server 3) Rebuild the server

AIM: Rebuilding the server takes 2 commands, one of them (to rebuild) takes some time and instead of me having to cd into the directory, stop the server, rebuild the script, then start it again... I'm trying to create a bash file to do it for me, so I can simply login and execute one command.

The directory I need to CD into is: /var/www/website/

The stop process I need to enter is: pm2 stop 0

The Rebuild process I need to enter is: yarn run build -- --release

The start process I need to enter is: pm2 start build/server.js

When I created a restartserver.sh file, I created it as follows:

#!/bin/bash
cd /var/www/website
pm2 stop 0
yarn run build -- --release
pm2 start build/server.js

When i try to run it by typing 'restartserver.sh' I get the error: -bash: restartserver.sh: command not found

I'm sure this is really easy for someone who has any idea about this sort of thing... but for my... I've no idea. Can anyone please help?

Thanks

P

9
  • 3
    Make it executable chmod +x restartserver.sh and execute it like ./restartserver.sh Commented Jul 18, 2018 at 16:23
  • BTW, typically you'd just want your command (and thus your script) to be called restartserver, not restartserver.sh. Scripts in the PATH define commands, and you run ls, not ls.elf; easy-install, not easy-install.py; etc. This also means you can rewrite your scripts in different languages without needing to modify every program that calls them to use a different name. Commented Jul 18, 2018 at 16:25
  • Thank you. I'll try and implement your comments now and I'll let you know how I get on Commented Jul 18, 2018 at 16:29
  • BTW, our Markdown here isn't GitHub-flavored -- triple backticks aren't special. If you want content to be treated as code (with syntax highlighting and the like), use four-space indents, or select a block and click the {} button. Commented Jul 18, 2018 at 16:29
  • By the way, is there a way to actually view the progress of the command being executed? Commented Jul 18, 2018 at 16:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.