cygwin shell scripting - how to pass values from command line to ssh remote command
Mark J. Reed
Wed Oct 15 00:02:00 GMT 2008
On Tue, Oct 14, 2008 at 2:59 PM, Z W wrote:
> 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:
echo >&2 "Usage: $0 [-h|-l loops|-m max_ms|-o offset_ms|-r ramp|-t threads]"
# default values
while getopts 'hl:m:o:r:t:' opt; do
case "$opt" in
h) usage 0;;
?) usage 1;;
shift $(( OPTIND - 1 ))
if (( $# )); then
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 <email@example.com>
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
More information about the Cygwin