Unix Shell - Command Line Arguments

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2006 > Command Line Arguments





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Command Line Arguments
BN

2006-11-30, 7:23 pm

Greetings

KSH Script, Will be using on SUN, AIX, and HP-UX

I want to run all the arguments (sql script) either in Parellel or in
Serail

Why does the following script gives an additional "&" for -p option at
the end

#!/bin/ksh

Arg_count=$#
integer count=0

case $1 in
-p)
echo "Parellel Execution\n"
set -A Args $*
echo "${Args[*]}"
until (( count == Arg_count ))
do
print "${Args[$count]} &"
((count=count + 1))
done;
;;
*)
echo "Serial Execution"
set -A Args $*
until (( count == Arg_count ))
do
print "${Args[$count]}"
((count=count + 1))
done
;;
esac


Script output:

u001/scripts> ./run_parallel.ksh -p sql1 sql2 sql3 sql4 sql5
Parellel Execution

sql1 sql2 sql3 sql4 sql5
sql1 &
sql2 &
sql3 &
sql4 &
sql5 &
&

/u001/scripts> ./run_parallel.ksh sql1 sql2 sql3 sql4 sql5
Serial Execution
sql1
sql2
sql3
sql4
sql5

Apprecaite your help

Barry Margolin

2006-11-30, 7:23 pm

In article <1164917725.923031.277500@79g2000cws.googlegroups.com>,
"BN" <bnsarma@gmail.com> wrote:

> Greetings
>
> KSH Script, Will be using on SUN, AIX, and HP-UX
>
> I want to run all the arguments (sql script) either in Parellel or in
> Serail
>
> Why does the following script gives an additional "&" for -p option at
> the end


Because you forgot to subtract 1 from Arg_count because of the -p option
that you're not printing.

>
> #!/bin/ksh
>
> Arg_count=$#
> integer count=0
>
> case $1 in
> -p)
> echo "Parellel Execution\n"
> set -A Args $*
> echo "${Args[*]}"
> until (( count == Arg_count ))
> do
> print "${Args[$count]} &"
> ((count=count + 1))
> done;
> ;;
> *)
> echo "Serial Execution"
> set -A Args $*
> until (( count == Arg_count ))
> do
> print "${Args[$count]}"
> ((count=count + 1))
> done
> ;;
> esac
>
>
> Script output:
>
> u001/scripts> ./run_parallel.ksh -p sql1 sql2 sql3 sql4 sql5
> Parellel Execution
>
> sql1 sql2 sql3 sql4 sql5
> sql1 &
> sql2 &
> sql3 &
> sql4 &
> sql5 &
> &
>
> /u001/scripts> ./run_parallel.ksh sql1 sql2 sql3 sql4 sql5
> Serial Execution
> sql1
> sql2
> sql3
> sql4
> sql5
>
> Apprecaite your help


--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Michal Nazarewicz

2006-12-02, 7:30 am

"BN" <bnsarma@gmail.com> writes:

> Greetings
>
> KSH Script, Will be using on SUN, AIX, and HP-UX
>
> I want to run all the arguments (sql script) either in Parellel or in
> Serail
>
> Why does the following script gives an additional "&" for -p option at
> the end
>
> #!/bin/ksh
>
> Arg_count=$#
> integer count=0
>
> case $1 in
> -p)
> echo "Parellel Execution\n"
> set -A Args $*
> echo "${Args[*]}"
> until (( count == Arg_count ))
> do
> print "${Args[$count]} &"
> ((count=count + 1))
> done;
> ;;
> *)
> echo "Serial Execution"
> set -A Args $*
> until (( count == Arg_count ))
> do
> print "${Args[$count]}"
> ((count=count + 1))
> done
> ;;
> esac


What's the use of an array here? Ie. why not do the following:

#v+
#! /bin/sh

case "$1" in
-p)
shift
echo Parellel Execution
for QUERY; do
echo "$QUERY &"
done
;;
*)
echo Serial Execution
for QUERY; do
echo "$QUERY"
done
esac
#v-


--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
Stephane CHAZELAS

2006-12-02, 7:30 am

2006-12-02, 10:18(+01), Michal Nazarewicz:
[...]
> #! /bin/sh


#! /bin/sh -

> case "$1" in
> -p)
> shift
> echo Parellel Execution
> for QUERY; do

[...]

Note that that syntax won't work with the Bourne shell, while

for QUERY do

and

for QUERY
do

and

for QUERY in ${1+"$@"}; do

will.

--
Stéphane
BN

2006-12-05, 1:20 pm

Stephane CHAZELAS wrote:
> 2006-12-02, 10:18(+01), Michal Nazarewicz:
> [...]
>
> #! /bin/sh -
>
> [...]
>
> Note that that syntax won't work with the Bourne shell, while
>
> for QUERY do
>
> and
>
> for QUERY
> do
>
> and
>
> for QUERY in ${1+"$@"}; do
>
> will.
>
> --
> St=E9phane



Greetings

Thank you all for your help.

In actual script, its just not echo, I will pass the echo through pipe
(|) to sqlplus (oracle) to get info from the database.

To save code, I am trying with the following code with out luck:

#!/bin/ksh

Arg_count=3D$#
integer count=3D0

LOGIN=3D"scott/tiger"

LOG_DIR=3D"$HOME/dbaroot/logs"

case $1 in
-p) ((Arg_count=3DArg_count -1)) # Decrease by one for -p
echo "Parellel Execution\n"
BG=3D"&" # to Push to BackGround to run in Parallel
;;
*)
echo "Serial Execution"
BG=3D"" # No Backgroud , run in Serial
;;
esac

set -A Args $*
until (( count =3D=3D Arg_count ))
do
# echo "select sysdate,user from dual;" |sqlplus -S $LOGIN
>$LOG_DIR/${Args[$count]}.log 2>&1 & # Works to push to Background

echo "select sysdate,user from dual;" |sqlplus -S $LOGIN
>$LOG_DIR/${Args[$count]}.log 2>&1 $BG # Doesn't Work to push to Backgr=

ound
((count=3Dcount + 1))
done


Appreciate your Help.
BN

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com