linux:bash_check_service
#!/bin/bash serviceno () { printf "\n$service is not running cannot continue...\n\n"; } serviceyes () { printf "\n$service is allready running cannot continue...\n\n"; } servicedead () { status=$(systemctl is-active $service); if [[ "$status" != "active" ]]; then serviceno ; exit; fi; } servicealive () { status=$(systemctl is-active $service); if [[ "$status" == "active" ]]; then serviceyes ; exit; fi; } # service="mysql" ; servicedead # Uncomment to check if service is not running and if not die. # service="mysql" ; servicealive # Uncomment to check if service is running and if so die.
linux/bash_check_service.txt · Last modified: 12/01/2024 15:00 by Allan