Process monitoring of Linux shell practice


Requirements: monitor the system for nginx. Every 3 seconds, the successful output test succeeds, the failed output test fails and restart the nginx service
The code is as follows (for reference only, the case is applicable to the author’s own MBP)

Echo "this is the first case of shell programming."

#Start of monitoring
while true
   #PS view status
   Echo "testing, please wait..."
   sleep 1
   echo "..."
   ps -ef | grep nginx | grep -v grep
   if [$? -ne 0]
      Echo "test result: failed"
      Echo "restart..."
      $(brew services start nginx)
      Echo "restart successful..."
      Echo "test result: success"

   Sleep for 3 seconds
   sleep 3;


Recommended Today

PHP Basics – String Array Operations

In our daily work, we often need to deal with some strings or arrays. Today, we have time to sort them out String operation <?php //String truncation $str = ‘Hello World!’ Substr ($STR, 0,5); // return ‘hello’ //Chinese string truncation $STR = ‘Hello, Shenzhen’; $result = mb_ Substr ($STR, 0,2); // Hello //First occurrence of […]