How to write a script that combines shell for loop with case
This article mainly explains "how to write a script that combines shell for loop and case". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to write a script that combines shell for loop and case".
Core code:
The code is as follows:
# / bin/bash
Set-x
HOSTS= "nginx mysql php-cgi"
For myhost in $HOSTS
Do
Count= (`ps aux | grep $myhost | grep-v grep | wc-l`)
Echo "$myhost"
Echo "$count"
If [$count-eq 0]; then
Case $myhost in
Nginx)
Cd / usr/local/webserver/nginx/sbin/
. / nginx
Echo "nginx has be down"
Sleep 5
Mysql)
/ etc/init.d/mysqld start
Echo "mysql has be down"
*)
Echo "what's the hell?"
Esac
Fi
Done
Set + x
Thank you for reading, the above is the content of "how to write a script that combines shell for loop and case". After the study of this article, I believe you have a deeper understanding of how to write a script that combines shell for loop and case, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!