Score:0

Wrong status is being echoing even after script ran successfully

cn flag
#!/bin/sh
serverStatus=$(ps aux | grep server1 -c)
serverStop='/server/myscripts/stopServer.sh server1'
serverStart='/server/myscripts/startServer.sh server1'

$serverStop
sleep 60

echo "$serverStatus"  

if [ $serverStatus -ne 2 ]
then
        echo 'Alert: App Server1 is down'
        
                $serverStart

else
        echo 'Alert: App Server1 is up and running'
        
fi

Output:

ADMU0116I: Tool information is being logged in file
           /server/myscripts/logs/server1/stopServer.log
ADMU0128I: Starting tool with the server profile
ADMU3100I: Reading configuration for server: server1
ADMU3201I: Server stop request issued. Waiting for stop status.
ADMU4000I: Server server1 stop completed.

2

Alert: App Server1 is up and running

Output should be:

ADMU0116I: Tool information is being logged in file
           /server/myscripts/logs/server1/stopServer.log
ADMU0128I: Starting tool with the server profile
ADMU3100I: Reading configuration for server: server1
ADMU3201I: Server stop request issued. Waiting for stop status.
ADMU4000I: Server server1 stop completed.

1

Alert: App Server1 is down
Nmath avatar
ng flag
It is not clear what you are asking. If you would like us to audit some script, you will need to provide the script. Please use [formatting with code fences](https://askubuntu.com/editing-help#code) so that we can accurately parse the information. If you cannot figure out the markdown formatting, please copy-paste as-is and we can help you with editing via moderation. In addition to providing the script, you should provide more context and details. Tell us what you are trying to do. You should also include the version and flavor of Ubuntu you are using
Preeti Rajgariya avatar
cn flag
$serverStop sleep 60 echo "$serverStatus" - Echo is not printing the correct status even if the server is stopped. I put sleep 60 also to increase the time to read the output but it did not work. -I am seeing the server is stopped successfully but its still giving me status as server is still up.
Preeti Rajgariya avatar
cn flag
So my if condition is not matching correctly.
Preeti Rajgariya avatar
cn flag
Below is my script. i am automating the server restart through this script and calling server stop and start script inside it.
bac0n avatar
cn flag
If you have lingering processes or your server spawns `grep -c` may give you 2. probably better to use `pgrep` with the pidfile option, or a systemd unit.
Preeti Rajgariya avatar
cn flag
serverStop='/server/myscripts/stopServer.sh server1 serverStart='/server/myscripts/startServer.sh server1' $serverStop sleep 60 echo "$serverStatus" if [ $serverStatus -ne 2 ] then echo 'Alert: App Server1 is down' $serverStart else echo 'Alert: App Server1 is up and running' fi
Preeti Rajgariya avatar
cn flag
Output is: ADMU0116I: Tool information is being logged in file /server/myscripts/logs/server1/stopServer.log ADMU0128I: Starting tool with the server profile ADMU3100I: Reading configuration for server: server1 ADMU3201I: Server stop request issued. Waiting for stop status. ADMU4000I: Server server1 stop completed. 2 Alert: App Server1 is up and running
Preeti Rajgariya avatar
cn flag
Output should be: output: ADMU0116I: Tool information is being logged in file /server/myscripts/logs/server1/stopServer.log ADMU0128I: Starting tool with the server profile ADMU3100I: Reading configuration for server: server1 ADMU3201I: Server stop request issued. Waiting for stop status. ADMU4000I: Server server1 stop completed. 1 Alert: App Server1 is down and server start command call
bac0n avatar
cn flag
As I said `grep server1 -c` counts anything containing *server1*, e.g., if you use a full path to your script or editor that contains *server1*. It will even count itself (that you can avoid with `grep -c '[s]erver1'`)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.