Wrote a script to stop MongoDB, the code snippet is as follows:
1#!/bin/Bash2 3 # Stop MONGO4Echo"Stop MongoDB ..."5Mongo_pid= ' Ps-ef | grep Mongod | Grep-v grep | Awk'{print $}'`6 if[[A${mongo_pid} = = A"' ]]7 Then8Echo"MongoDB is not running ..."9 ElseTenKill-2${mongo_pid} OneSleep5 A ifPs-ef | Grep-v grep | grep-Q Mongod - Then -Echo"MongoDB Stop failed" the Else -Echo"MongoDB Stop Successful" - fi -Fi
The execution method is
SH stop.sh
Perform normally on CentOS and execute on Ubuntu with an error:
Hey i'm wondering, Brother's code is right Ah, find a half-day did not find the reason, help StackOverflow, find the reason:
Swap with the following script execution method will not be an error
./stop.sh
Check out what Dash is:
In Debian and Ubuntu,/bin/sh is already pointing to dash, which is a different shell from bash, which is mostly for scripting, not interactive, it's faster, but it's much less powerful than bash, and the syntax adheres to the POSIX standard.
Ubuntu with less, pit big, record under
The ubuntu/bin/sh of the pit daddy