Hướng dẫn tạo script check service running or not
Giả sử máy CentOS của bạn có dịch vụ httpd hay bị down, bạn có thể tạo script sau để check 1 phút/lần , nếu phát hiện dịch vụ bị down thì tự động start lại
1. Tạo file /root/check.sh với nội dung sau:
==========================
#!/bin/bash service=httpd if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 )) then echo "$service is running!!!" else /etc/init.d/$service start fi
==============================
2. Vào crontab -e đặt lệnh, 1 phút check 1 lần
# crontab -e
*/1 * * * * sh /root/check.sh
http://www.akamaras.com/linux/linux-...f-its-stopped/
Chúc bạn thành công.