#How can you setup a executable file to run 3 cmds. The first needs password

1 messages · Page 1 of 1 (latest)

rancid pagoda
#

Im trying to make it easier to startup my minecraft server because i keep forgetting the command. i could just do a text file and copy paste it but i thought there was a way to make a script. The 3 commands i need run is:

sudo su crafty
cd /var/opt/minecraft/crafty
./run_crafty.sh

in that order.
So far ive put that in a text file and i have it executable which allows me to run in terminal. The problem is it asks for sudo (fine) but then stops there. doesnt change directory or anything. Sorry im quite new to terminal things.

smoky laurel
rancid pagoda
#

I was trying to learn about that. There was one forum post that was doing this command.
apt update && apt upgrade -y
is the "&&" linking two commands together?

#

ah. kinda, runs the next command if last command succeeds

#

Im bad at this kinda stuff. This is what i put in a file named server.sh

#!/bin/bash
sudo su crafty && cd /var/opt/minecraft/crafty && ./run_crafty.sh

then i use ./server.sh to run it. asks for password for sudo and same problem. It does sudo su crafty and nothing else.

#

Ive also tried
#!/bin/bash
sudo su crafty &&
cd /var/opt/minecraft/crafty &&
./run_crafty.sh