This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cygwin shell scripting - how to pass values from command line to ssh remote command


On Tue, Oct 14, 2008 at 2:59 PM, Z W wrote:
> Question:
> How can I pass arguments on command line with test.sh such that
> variables MAX_MS, OFFSET_MS, THREADS, RAMP and LOOPS
> could receive the argument parameters as opposed to hardcoding the numbers ?

This isn't really a cygwin question; there are lots of shellscripting
tutorials on the web, which I recommend you look for.  Meanwhile,
however, try this:

#!/bin/bash

function usage
{
    echo >&2 "Usage: $0 [-h|-l loops|-m max_ms|-o offset_ms|-r ramp|-t threads]"
    exit $1
}


# default values
loops=2
max_ms=100
offset_ms=89900
ramp=1
threads=4

while getopts 'hl:m:o:r:t:' opt; do
    echo opt=$opt
    case "$opt" in
        h) usage 0;;
        l) loops="$OPTARG";;
        m) max_ms="$OPTARG";;
        o) offset_ms="$OPTARG";;
        r) ramp="$OPTARG";;
        t) threads="$OPTARG";;
        ?) usage 1;;
    esac
done

shift $(( OPTIND - 1 ))

if (( $# )); then
    usage 1
fi

ssh localhost 'cd /cygdrive/c/apps/bin && LOOPS="'"$loops"'"
MAX_MS="'"$max_ms"'" OFFSET_MS="'"$offset_ms"'" RAMP="'"$ramp"'"
THREADS="'"$threads"'" nohup ./start.sh & ps -efW | grep java'

That ssh command should be all on one line.  Careful with the
sequences of quotation marks.  The idea is to build a command string
that includes literal quotation marks intermixed with the quoted
expansion of local variables.

Also note that if all you're looking to getting out of that ps |grep
java line is the PID, you can just use $!.

-- 
Mark J. Reed <markjreed@gmail.com>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]