Really minor shell script question. - Linux

This is a discussion on Really minor shell script question. - Linux ; Hi there, I probably should feel really stupid for asking such a question, however, I'm not familiar with *any* type of shell scripting at all, and I have never had a use for it, until now, and it's just a ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Really minor shell script question.

  1. Really minor shell script question.

    Hi there,
    I probably should feel really stupid for asking such a question,
    however, I'm not familiar with *any* type of shell scripting at all, and I
    have never had a use for it, until now, and it's just a minor thing. I
    have two Linux boxes, one with all the brains and stuff, and the other
    with just a basic setup, with SSH on it to access the first one, so that
    more then one person can login at once. (Because the first one is on an
    external Internet connection, we do not have telnet on it, we only permit
    SSH connections.)
    I need to be able to have a script display a menu of six choices,
    and be able to run SSH one of six ways based upon whatever choice the user
    makes. I've found the dialog tool, and can use that, most likely, but I
    need to know how to capture the output from it (which is redirected to
    stderr), from the shell, and make a judgement on how to run SSH. If this
    were DOS batch, I could do it probably just fine, 'cuz dialog would
    probably just set errorlevel, but alas, there is no mechanism like that,
    here.
    Can someone help me out on this? It'd be much appreciated.

    Thanks,
    Michael

    --
    Michael B. Trausch AIM: MBTrausch
    E-mail: fd0man@chadeux.homelinux.net
    Web: http://chadeux.homelinux.net/users/fd0man/
    -----------------------------------------------------------------
    To send me mail, you MUST put "D O G X P 1 8 0" somewhere
    in the mail message, and without spaces between the letters.
    -----------------------------------------------------------------
    People will forget what you said and what you did,
    but they will never forget how you made them feel.


  2. Re: Really minor shell script question.

    On Fri, 17 Oct 2003 23:58:03 -0500, Michael B. Trausch wrote:

    > Hi there,
    > I probably should feel really stupid for asking such a question,
    > however, I'm not familiar with *any* type of shell scripting at all, and I
    > have never had a use for it, until now, and it's just a minor thing. I
    > have two Linux boxes, one with all the brains and stuff, and the other
    > with just a basic setup, with SSH on it to access the first one, so that
    > more then one person can login at once. (Because the first one is on an
    > external Internet connection, we do not have telnet on it, we only permit
    > SSH connections.)
    > I need to be able to have a script display a menu of six choices,
    > and be able to run SSH one of six ways based upon whatever choice the user
    > makes. I've found the dialog tool, and can use that, most likely, but I
    > need to know how to capture the output from it (which is redirected to
    > stderr), from the shell, and make a judgement on how to run SSH. If this
    > were DOS batch, I could do it probably just fine, 'cuz dialog would
    > probably just set errorlevel, but alas, there is no mechanism like that,
    > here.


    http://www.nerdlabs.org/documents/shell_redirection.php

    errorresult does exist, it just has the unlikely name $? - also its set
    by almost everything so you must read it hard up against the command

    /pathto/myprogram
    errorresult=$?
    echo "Myprogram resturned error result $errorresult"



    Run a command from within a shell, saving the results from stdout
    myoutput=`mycommand`

    Also see "read" "xmessage"

    Plain shell example of read

    echo "please select a menu option 1,2,3,4"
    echo -n "option>"
    read myvar
    if [ $myvar == "1" ]; then
    stuff
    fi


    Or
    echo "please select a menu option 1,2"
    echo -n "option>"
    read myvar
    case $myvar in
    "1")
    echo "user says 1"
    ;;

    "2") echo "user says 2"
    ;;

    *)
    echo "users says any old ..."
    ;;
    esac




  3. Re: Really minor shell script question.

    On 2003-10-19, root wrote:
    >
    > http://www.nerdlabs.org/documents/shell_redirection.php
    >
    > errorresult does exist, it just has the unlikely name $? - also its set
    > by almost everything so you must read it hard up against the command
    >
    > /pathto/myprogram
    > errorresult=$?
    > echo "Myprogram resturned error result $errorresult"
    >

    [snip...]

    Wow. Sweet!

    >
    >
    > Run a command from within a shell, saving the results from stdout
    > myoutput=`mycommand`
    >

    [snip...]

    Is there any way to save the results from stderr, though? :-/

    I'll check out the link that you posted to me. Thanks a ton, really!

    Thanks again,
    Mike

    --
    Michael B. Trausch AIM: MBTrausch
    E-mail: fd0man@chadeux.homelinux.net
    Web: http://chadeux.homelinux.net/users/fd0man/
    -----------------------------------------------------------------
    To send me mail, you MUST put "D O G X P 1 8 0" somewhere
    in the mail message, and without spaces between the letters.
    -----------------------------------------------------------------
    People will forget what you said and what you did,
    but they will never forget how you made them feel.


  4. Re: Really minor shell script question.

    Michael B. Trausch's on Sunday
    19 October 2003 04:52 pm in %group contained all or some of:

    > Is there any way to save the results from stderr, though? :-/


    Redirect stderr so that it appends to a file like this: 2>> logfile.errors

    Check the shell syntax of the shell you are using.

    If you are writing your own scripts, don't need to use stderr at all. You
    can open a log file and write all interesting stuff to it. Debugging info
    and errors, for instance. If you are executing some existing command that
    wrties to stderr, then type the command and arguments followed by the
    redirection indicated above.

    If you want it be on both the screen and in the file, check out "tee" and
    pipe through it.

    Good luck.

  5. Re: Really minor shell script question.

    On 2003-10-20, Lynn Dobbs wrote:
    > Michael B. Trausch's on Sunday
    > 19 October 2003 04:52 pm in %group contained all or some of:
    >
    >> Is there any way to save the results from stderr, though? :-/

    >
    > Redirect stderr so that it appends to a file like this: 2>> logfile.errors
    >
    > Check the shell syntax of the shell you are using.
    >


    I know how to do that.

    I need to know how to use the output of stderr from an application (the
    output of which is a single character that I could put into a variable)
    to control what will happen next in my shell script.

    The program in question is cdialog (e.g., dialog), a terminal based
    dialog screen utility that can be called from any language program.

    - Mike

    --
    Michael B. Trausch AIM: MBTrausch
    E-mail: fd0man@chadeux.homelinux.net
    Web: http://chadeux.homelinux.net/users/fd0man/
    -----------------------------------------------------------------
    To send me mail, you MUST put "D O G X P 1 8 0" somewhere
    in the mail message, and without spaces between the letters.
    -----------------------------------------------------------------
    People will forget what you said and what you did,
    but they will never forget how you made them feel.


  6. Re: Really minor shell script question.

    On Mon, 20 Oct 2003 15:11:46 -0500, Michael B. Trausch wrote:

    > On 2003-10-20, Lynn Dobbs wrote:
    >> Michael B. Trausch's on Sunday
    >> 19 October 2003 04:52 pm in %group contained all or some of:
    >>
    >>> Is there any way to save the results from stderr, though? :-/

    >>
    >> Redirect stderr so that it appends to a file like this: 2>> logfile.errors
    >>
    >> Check the shell syntax of the shell you are using.
    >>

    >
    > I know how to do that.
    >
    > I need to know how to use the output of stderr from an application (the
    > output of which is a single character that I could put into a variable)
    > to control what will happen next in my shell script.
    >
    > The program in question is cdialog (e.g., dialog), a terminal based
    > dialog screen utility that can be called from any language program.
    >
    > - Mike


    The crap way would be to hold it in a file !



    #Run program and echo stdout and stderr to a file
    /pathto/myexec 2&1>>myfile.txt
    #Put the contents of the file into a variable
    $e=`cat myfile.txt`
    echo output was $e

    Im not a person who says this a lot, but RTFM ! The bash scripting guides
    from google will help as will man bash. Lookup the use of `command`
    (backquote ` ) This can be used for lots of fun stuff.



  7. Re: Really minor shell script question.

    On 2003-10-21, root wrote:
    >
    > The crap way would be to hold it in a file !
    >
    > #Run program and echo stdout and stderr to a file
    > /pathto/myexec 2&1>>myfile.txt
    > #Put the contents of the file into a variable
    > $e=`cat myfile.txt`
    > echo output was $e
    >
    > Im not a person who says this a lot, but RTFM ! The bash scripting guides
    > from google will help as will man bash. Lookup the use of `command`
    > (backquote ` ) This can be used for lots of fun stuff.
    >


    Ugh... I'm a blonde...

    I knew about the use of `command` and I've used it to setup
    the environment and variables and such before... Why I didn't
    think to use it, I don't know.

    Wow. I feel stupid. My apologies.

    - Mike

    --
    Michael B. Trausch AIM: MBTrausch
    E-mail: fd0man@chadeux.homelinux.net
    Web: http://chadeux.homelinux.net/users/fd0man/
    -----------------------------------------------------------------
    To send me mail, you MUST put "D O G X P 1 8 0" somewhere
    in the mail message, and without spaces between the letters.
    -----------------------------------------------------------------
    People will forget what you said and what you did,
    but they will never forget how you made them feel.


+ Reply to Thread