0

I wanted to understand how to create a script sh that allows me to see if an additional script functions correctly.

For now this is the script that I created.

if /run.sh status
   echo "$SERVICEXE running, everything is fine"
else
   echo "$SERVICEXE is not running!" 
fi

At this point, I would like it if checking the status of run.sh proves that it is not running, (output: No server running) that this is restarted. But I would not know how to check if the string (/run.sh status) issues this result then that this service is restarted. I would not use the pid because you will create many similar processes, and I think the script would conflict. I hope I explained

0

$? gives you the status of last executed command:called as exit status if success its 0 else can be any number

root@hackaholic:~# echo "hello"
hello
root@hackaholic:~# echo $?
0
root@hackaholic:~# ps
PID TTY          TIME CMD
21005 pts/2    00:00:00 bash
21051 pts/2    00:00:00 ps
root@hackaholic:~# echo $?
0
root@hackaholic:~# junk
bash: junk: command not found
root@hackaholic:~# echo $?
127
root@hackaholic:~# 
  • Work, but not in my case. when i run run.sh status, i can get two types of answers. Server Seems to have died and Server is running, but either way I get to the command echo $? the number 0. – Metallic01 Nov 25 '14 at 16:06
  • in ur script what is status?? – Hackaholic Nov 25 '14 at 16:11
  • I'll explain the situation better. Using teamspeak 3 have a command to start the server that is run.sh start, if you want to turn it off run.sh stop and if you want to see if the server is active or not, uses run.sh status. This as mentioned above, i can get two types of answers. Server Seems to have died and Server is running. I want to make sure that if the server returns "Server Seems to have died" which starts a new one (run.sh start), but if I get "Server is running" that does not run anything. – Metallic01 Nov 25 '14 at 16:16
  • you check pid of program??? – Hackaholic Nov 25 '14 at 16:19
  • I cant check pid, because programs creates many pid for the same process. – Metallic01 Nov 25 '14 at 16:21

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.