0

I am learning to use zenity with some simple bash scripts I wrote. I need to compare the command output of a list selection with a string. Everything I find uses variables. I am NOT using a variable I am using the direct output of the zenity list selection and need to compare it to a string for an if-else statement.

This is the example of what I am trying. I have tried many things and seem to be stuck. I don't need a to hear obnoxious statements of how stupid the script is. The script doesn't matter, I am using a simple script to learn more how to use zenity.

zenity --list --width 390 --height 450 \
--column "Option" \
--column "Action" \
--column  "Service" \
FSTAT  "FTP Server Status" "Pure FTP Server" \
FRSTRT "Start FTP Server" "Pure FTP Server" \
FFRLD "Force Reload FTP Server" "Pure FTP Server" \
FSTP "Stop FTP Server" "Pure FTP Server" \
SSTAT "SSH Server Status" "SSHD Server" \
SSTRT "SSH Server Start" "SSHD Server" \
SSTP "Stop SSH Server" "SSHD Server" \
ASTAT "Apache Server Status" Apache2 \
ASTRT "Start Apache Server" Apache2 \
ASTP "Stop Apache Server" Apache2 \
C80 "Check Port 80" Servers \
KPROC "Kill Process" "PID Service"


if [[ $? = "FSTAT" ]]; then
    echo "Pure FTP Server Status"
    echo "Press q to quit"
    service pure-ftpd status
elif [[ $? = "FRSTRT" ]]; then
    echo "Restart Pure FTP Server"
    service pure-ftpd restart
elif [[ $? = "FFRLD" ]]; then
    echo "Force-Reload Pure FTP Server"
    service pure-ftpd force-reload  
elif [[ $? = "FSTP" ]]; then
    echo "Stop Pure FTP Server"
    service pure-ftpd stop
elif [[ $? = "SSTAT" ]]; then
    echo "Press q to quit"
    echo "SSHD Server Status"
    service sshd status 
elif [[ $? = "SSTRT" ]]; then
    echo "Start SSHD Server"
    service sshd start
elif [[ $? = "SSTP" ]]; then
    service sshd stop
    echo "Stop SSHD Server"
elif [[ $? = "ASTAT" ]]; then
    echo "Press q to quit"
    echo "Apache2 Server Status"
    service apache2 status
elif [[ $? = "ASTRT" ]]; then
    echo "Start Apache2 Server"
    service apache2 start   
elif [[ $? = "ASTP" ]]; then
    echo "Stop Apache2 Server"
    service apache2 stop    
elif [[ $? = "C80" ]]; then
    echo "Check Port 80"
    sudo netstat -tulpn | grep :80  
elif [[ $? = "KPROC" ]]; then
# ADD ZENITY STATEMENT HERE
    echo "Kill Process"m
else
exit 0
fi
  • Please take a moment to properly format your question (there is help available in the editor). – larsks Jan 24 '23 at 20:13
  • 1
    There, sorry that should be better. – OldSoldier Jan 24 '23 at 20:17
  • 1
    `$?` is not the output of the command, it's the numeric exit status. Use `variable=$(command)` to capture the output to a variable. – Barmar Jan 24 '23 at 20:17
  • Yeah, `$?` is only ever a one-byte number, between 0 and 255. No way for it to be anything else. If the command "succeeds", whatever it considers that to be, it exits with code 0; if it doesn't completely succeeed, it returns a nonzero value. – Mark Reed Jan 24 '23 at 20:20
  • @Barmar - That makes sense thanks. Going to test that out now. – OldSoldier Jan 24 '23 at 20:20
  • AND they closed my question. This is exactly why I never use boards like this. It may be similar to another question, but I don't understand it or I wouldn't ask the question i the first place. If I completely understood it perhaps I would have found the answer already. Just marking it as duplicate and closing it is obnoxious! Thank you to those who actually HELPED me with their answers. I now understand better what I need to do. – OldSoldier Jan 24 '23 at 20:24

0 Answers0