Find the answer to your Linux question:
Results 1 to 4 of 4
I'm currently practicing and learning some basic scripting and was hoping that someone can help me with something. basically I'm trying to get an "if" statement to read from the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2010
    Posts
    34

    Practicing and learning Scripting.


    I'm currently practicing and learning some basic scripting and was hoping that someone can help me with something.

    basically I'm trying to get an "if" statement to read from the output of a zenity command, and then go on to execute another command based on the result of the if. I've tried heaps of different things and tried looking it (though not 100% what to look for) so far what is as shown below.

    zenity --list --radiolist \
    --title="Choose the Bugs You Wish to View" \
    --column="select" --column="Severity" --column="Description" \
    1 normal "GtkTreeView crashes on multiple selections" \
    2 high "GNOME Dictionary does not handle proxy" \
    3 critical "Menu editing does not work in GNOME 2.0"



    if [ "$VAR" == normal ]; then
    zenity --info --title='Test' text='You selected normal'
    elif [ "$VAR" == high ]; then
    zenity --info --title='Test' text='You selected high'
    elif [ "$VAR" == critical ]; then
    zenity --info --title='Test' text='You selected critical'
    fi
    I'm still learning this stuff so my apologies if I've missed something obvious. So can any one give me an example of what to put into this script to merge the two sections together so that they work.

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,286
    Hi.

    I modified your script as:
    Code:
    #!/usr/bin/env bash
    
    # @(#) s1	Demonstrate zenity return of user selection.
    
    # Utility functions: print-as-echo, print-line-with-visual-space.
    pe() { for i;do printf "%s" "$i";done; printf "\n"; }
    pl() { pe;pe "-----" ;pe "$*"; }
    
    VAR=$(zenity --list --radiolist \
    --title="Choose the Bugs You Wish to View" \
    --column="select" --column="Severity" --column="Description" \
    1 normal "GtkTreeView crashes on multiple selections" \
    2 high "GNOME Dictionary does not handle proxy" \
    3 critical "Menu editing does not work in GNOME 2.0" \
    )
    
    pe " VAR is $VAR"
    pe
    
    if [ "$VAR" == normal ]; then
    pe " debug, VAR as $VAR found."
    # zenity --info --title='Test' text='You selected normal'
    zenity --info --title='Test' --text='You selected normal'
    elif [ "$VAR" == high ]; then
    zenity --info --title='Test' text='You selected high'
    elif [ "$VAR" == critical ]; then
    zenity --info --title='Test' text='You selected critical'
    fi 
    
    exit 0
    producing:
    Code:
    % ./s1
     VAR is normal
    
     debug, VAR as normal found.
    which caused your VAR to be set, and with the GUI interaction behaving as I would expect, etc. You should be able to finish it ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Just Joined!
    Join Date
    Mar 2010
    Posts
    34
    Quote Originally Posted by drl View Post
    Hi.

    I modified your script as:
    Code:
    #!/usr/bin/env bash
    
    # @(#) s1	Demonstrate zenity return of user selection.
    
    # Utility functions: print-as-echo, print-line-with-visual-space.
    pe() { for i;do printf "%s" "$i";done; printf "\n"; }
    pl() { pe;pe "-----" ;pe "$*"; }
    
    VAR=$(zenity --list --radiolist \
    --title="Choose the Bugs You Wish to View" \
    --column="select" --column="Severity" --column="Description" \
    1 normal "GtkTreeView crashes on multiple selections" \
    2 high "GNOME Dictionary does not handle proxy" \
    3 critical "Menu editing does not work in GNOME 2.0" \
    )
    
    pe " VAR is $VAR"
    pe
    
    if [ "$VAR" == normal ]; then
    pe " debug, VAR as $VAR found."
    # zenity --info --title='Test' text='You selected normal'
    zenity --info --title='Test' --text='You selected normal'
    elif [ "$VAR" == high ]; then
    zenity --info --title='Test' text='You selected high'
    elif [ "$VAR" == critical ]; then
    zenity --info --title='Test' text='You selected critical'
    fi 
    
    exit 0
    producing:
    Code:
    % ./s1
     VAR is normal
    
     debug, VAR as normal found.
    which caused your VAR to be set, and with the GUI interaction behaving as I would expect, etc. You should be able to finish it ... cheers, drl
    Thanks, this worked a treat and I have now been able to rewrite it so for the purpose that I had in mind for it. I'll keep this one somewhere safe so that I can refer back to it in future.

    Another idea that I'm interested in is a script that will run a constant ping until it gets a response, then once it receives a reply from the ping to the specified ip num, it executes the next command.
    I know how to run a the ping and I know the command that I want to run. I just don't know how to get a script acknowledge the reply from the ping to the say ok run the next command.

    I have tried tinkering with the you one that you posted above and haven't been able to get it going. Are you (or someone else) able to point me in the right direction.

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,286
    Hi.

    Please start a new thread for a new question. That provides better results for others using the forum search feature as a knowledge base.

    Also include a short example of your attempt(s) -- like you did in your post here. Thanks ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •