User Tools

Site Tools


wm:fvwm:scripts:gen-services-menu.sh
# Gen Services Menu
# Generate FVWM menu for a list of services
# Usage : gen-servicess-menu.sh MenuName
 
# Variable that stores a list of services to control
SERVICESLIST="cups-browsed sshd bluetooth teamviewerd"
# Variable that store the command to start/restart/stop/status the services:
SERVICECMD="sudo systemctl"
# Variable with menu separator
SEPARATOR="AddToMenu $1 \"\" Nop"
 
# Function that check the status of a network
function CHECKSERVICE() {
    # Check if network $1 is in status "dead"
    sudo systemctl status $1 | grep -q \(dead\)
    # if it is
    if [ $? -eq 0 ]
    then
        return 1
    else
        return 0
    fi
}
 
 
for SERVICE in $SERVICESLIST
do
    #check status of this service
    CHECKSERVICE $SERVICE
    #if down
    if [ $? -ne 0 ]
    then
        # Write in the menu to start it
        echo "AddToMenu $1 \"Start &$SERVICE\" Exec exec urxvt -e $SERVICECMD start $SERVICE" 
        echo $SEPARATOR
    else
        # Write in the Menu to restart it
        echo "AddToMenu $1 \"Restart $SERVICE\" Exec exec urxvt -e $SERVICECMD restart $SERVICE"
        # Or stop it
        echo "AddToMenu $1 \"Stop $SERVICE\" Exec exec urxvt -e $SERVICECMD stop $SERVICE"
        echo $SEPARATOR
    fi
done
wm/fvwm/scripts/gen-services-menu.sh.txt · Last modified: 2021/12/29 21:09 by warnaud