Execution problem on kornshell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution problem on kornshell
# 1  
Old 12-16-2010
MySQL Execution problem on kornshell

HI,

Requirement: I need to pass space between argument value for the paramter "GPG_PUBLIC_UID" but whenever i use single quotes or double quotes while supplying value for the arguments to the script, i see the value of the field "GPG_PUBLIC_UID" is getting splitted and my script fails to process with the actual value.
eg: i am trying to pass GPG_PUBLIC_UID= "ABCD DEFG" and my script splits them as GPG_PUBLIC_UID = "ABCD".

My script :
Code:
#!/bin/ksh
set -x
this=${0##*/};
params=$*
#--Read all parameters passed
for p in $params ;do
        eq=`echo $p|grep = >/dev/null 2>&1;echo $?`
        if [[ $eq -eq 0 ]]; then
                exc=`echo $p|egrep -e "SRC_DIR=|SRC_FILE=|TGT_DIR=|TGT_FILE=|MID_USER=|MID_HOST=|MID_DIR=|GPG_PUBLIC_UID=|REMOTE_USE
R=|REMOTE_HOST=|REMOTE_DIR=|TOUCH_FILE=">/dev/null 2>&1;echo $?`
                if [[ $exc -eq 0 ]]; then
                        name=`echo ${p%%=*}`
                        value=`echo ${p##*=}`
                        export $name=$value
                fi
        fi
done
#--As any required parameter missing check
echo "\nChecking if [[ -z ${SRC_DIR} ]] || [[ -z ${SRC_FILE} ]] || [[ -z ${TGT_DIR} ]] || [[ -z ${TGT_FILE} ]] || [[ -z ${MID_USER}
]] || [[ -z ${MID_HOST} ]] || [[ -z ${MID_DIR} ]] || [[ -z ${GPG_PUBLIC_UID} ]] || [[ -z ${REMOTE_USER} ]] || [[ -z ${REMOTE_HOST} ]
] || [[ -z ${REMOTE_DIR} ]] ||[[ -z ${TOUCH_FILE} ]]"
if [[ -z ${SRC_DIR} ]] || [[ -z ${SRC_FILE} ]] || [[ -z ${TGT_DIR} ]] || [[ -z ${TGT_FILE} ]] || [[ -z ${MID_USER} ]] || [[ -z ${MID
_HOST} ]] || [[ -z ${MID_DIR} ]] || [[ -z ${GPG_PUBLIC_UID} ]] || [[ -z ${REMOTE_USER} ]] || [[ -z ${REMOTE_HOST} ]] || [[ -z ${REMO
TE_DIR} ]] || [[ -z ${TOUCH_FILE} ]];
....
....

Pls guide me to proceed further.

Last edited by Scott; 12-16-2010 at 05:43 PM.. Reason: Please use code tags
# 2  
Old 12-16-2010
Show me how your passing the variables as this seems to work for me.
Code:
cat xxx.ksh
 
#!/bin/ksh
echo "|$0|"
echo "|$1|"

Called like this:
Code:
./xxx.ksh GPG_PUBLIC_UID="ABCD DEFG"
|./xxx.ksh|
|GPG_PUBLIC_UID=ABCD DEFG|


Last edited by Scott; 12-16-2010 at 05:44 PM.. Reason: Code tags
# 3  
Old 12-16-2010
Replace
Code:
params=$*
for p in $params ;do

by
Code:
 for p in "$@"; do

# 4  
Old 12-16-2010
Execution problem on kornshell

Thanks for response.

i changed as below and ran the script but i see the value getting splitted again Smilie
Code:
params="$@"
echo " $Params is the params variable value"
#--Read all parameters passed
for p in $params ;do

Argument which i pass to script :
Code:
$DW_EXE/shell_handler.ksh dw_ad_users_info_fexp extract dw_ase.dw_ad_users_info_file_encrypt_test.ksh SRC_DIR=$DW_OUT/extract/dw_ase \
SRC_FILE=dw_ad_users_info_col_split.dat TGT_DIR=$DW_OUT/extract/ TGT_FILE=DD_2010-11-22.dat.gz.gpg \
MID_USER=ditg MID_HOST=aaaaa.sjc.com MID_DIR=/export/home/ \
GPG_PUBLIC_UID='aaaa data' REMOTE_USER=abdec \
 REMOTE_HOST=dev04.sjc.com REMOTE_DIR=/export/home/ TOUCH_FILE=DD_2010-11-22.done


Last edited by Scott; 12-16-2010 at 07:55 PM.. Reason: Code tags
# 5  
Old 12-16-2010
Seems to be working as expected for me (in bash and ksh):

Code:
$ cat shell_handler.ksh 
#!/bin/ksh
params="$@"
echo " $Params is the params variable value"
#--Read all parameters passed
for p in $params ;do
    echo "|$p|"
done
 
$ ./shell_handler.ksh dw_ad_users_info_fexp extract dw_ase.dw_ad_users_info_file_encrypt_test.ksh SRC_DIR=$DW_OUT/extract/dw_ase \
> SRC_FILE=dw_ad_users_info_col_split.dat TGT_DIR=$DW_OUT/extract/ TGT_FILE=DD_2010-11-22.dat.gz.gpg \
> MID_USER=ditg MID_HOST=aaaaa.sjc.com MID_DIR=/export/home/ \
> GPG_PUBLIC_UID='aaaa data' REMOTE_USER=abdec \
> REMOTE_HOST=dev04.sjc.com REMOTE_DIR=/export/home/ TOUCH_FILE=DD_2010-11-22.done
  is the params variable value
|dw_ad_users_info_fexp|
|extract|
|dw_ase.dw_ad_users_info_file_encrypt_test.ksh|
|SRC_DIR=/extract/dw_ase|
|SRC_FILE=dw_ad_users_info_col_split.dat|
|TGT_DIR=/extract/|
|TGT_FILE=DD_2010-11-22.dat.gz.gpg|
|MID_USER=ditg|
|MID_HOST=aaaaa.sjc.com|
|MID_DIR=/export/home/|
|GPG_PUBLIC_UID=aaaa|
|data|
|REMOTE_USER=abdec|
|REMOTE_HOST=dev04.sjc.com|
|REMOTE_DIR=/export/home/|
|TOUCH_FILE=DD_2010-11-22.done|


Last edited by Chubler_XL; 12-16-2010 at 08:04 PM..
# 6  
Old 12-16-2010
Execution problem on kornshell

Hi,

As you see the output:
Code:
 MID_HOST=aaaaa.sjc.com|
|MID_DIR=/export/home/|
|GPG_PUBLIC_UID=aaaa|
|data|

See the "aaaa data" is getting splitted inside the script which has to be changed like |GPG_PUBLIC_UID=aaaa data| .

Last edited by Scott; 12-16-2010 at 07:57 PM..
# 7  
Old 12-16-2010
OK, I see the problem. How about this.

Code:
#--Read all parameters passed
while [ $# -gt 0 ]
do
    case "$1" in
        SRC_DIR=*|SRC_FILE=*|\
        TGT_DIR=*|TGT_FILE=*|\
        MID_USER=*|MID_HOST=*|MID_DIR=*|GPG_PUBLIC_UID=*|\
        REMOTE_USER=*|REMOTE_HOST=*|REMOTE_DIR=*|TOUCH_FILE=*) \
            export ${1%%=*}="${1##*=}" ;;
    esac
    shift
done
#--As any required parameter missing check
echo "GPG_PUBLIC_UID=${GPG_PUBLIC_UID}"


Last edited by Chubler_XL; 12-16-2010 at 08:26 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Execution problem

How to search a pattern from multiple files... i used the command suppose the pattern name is xxx grep xxx (file1-o- file2-o- file3) Thanks in advance (4 Replies)
Discussion started by: ksakil
4 Replies

2. Shell Programming and Scripting

Execution problem

Hi, I have been trying to run a simple script CONFIG_FILE="/jay/check" . . . for i in `cat $CONFIG_FILE` do loc=`echo $i | cut -d "|" -f2` var=$(find $loc -mtime -1|wc -l) if then echo $loc has files older than 1 day fi done . . . (2 Replies)
Discussion started by: jayii
2 Replies

3. Shell Programming and Scripting

Execution problem

hi all, when i tried executing the script by giving following command $ sh test.sh <parameter> it shows the following output: <none> status code=0 Previously it was working fine.But now its showing this output. (1 Reply)
Discussion started by: sanjay mn
1 Replies

4. UNIX for Dummies Questions & Answers

execution problem

HI I am trying to check the status of port using command /code: netstat -an | grep port /Output: *.2009 *.* 0 0 65535 0 LISTEN what i am trying to do is i want to grep only status Wether the port is established/listen if so show ok else... (1 Reply)
Discussion started by: esumiba
1 Replies

5. UNIX for Dummies Questions & Answers

execution problem

Hi I am automating my few commands out of which one command is tail -f running.logs when i run this command it does not automatically exit and show prompt (#) what would i do so that it will exit out automatically after few seconds and move to the next command without using ... (4 Replies)
Discussion started by: esumiba
4 Replies

6. UNIX for Dummies Questions & Answers

execution problem

Hi i have a file in which there are three fields code: 919804199233 404911130003916 357266044991350F and now i want to add two more fields i.e. code: 919804199233 404911130003916 357266044991350F ms 123 how can i do it using command line and if have a file of 100... (8 Replies)
Discussion started by: esumiba
8 Replies

7. UNIX for Dummies Questions & Answers

execution problem

Hi i am using expect module and trying to login using following code. ssh 127.0.0.1 expect "word:" send "$password \n" kindly let me know the login script using expect module (1 Reply)
Discussion started by: esumiba
1 Replies

8. Shell Programming and Scripting

execution problem with grep

how to use grep word from sentence grep -o "hai" haighaihaihai Is above cmd possible in linux ? can any one help me? Thanks, (5 Replies)
Discussion started by: kavi.mogu
5 Replies

9. UNIX for Dummies Questions & Answers

Problem with Crontab execution

Hi I have shell script to excute the SQL script.And i have scheduled those shell script in crontab.But the Shell script is not running timely and i got the below error Crontab entry 15 05 17 7 * /export/home/vcpsapp/vcps/stat.sh Output Your "cron" job on uspxivus16... (3 Replies)
Discussion started by: mak_boop
3 Replies

10. Shell Programming and Scripting

Problem in Connecting to Oracle Database using KornShell

Hello, I am very new to Scripting. I am having a Kornshell Script below for connecting to Oracle database. But getting an error while executing it. #!/bin/ksh ssh -X root@192.168.2.127 <perimuka> sleep 5 su - oracle sqlplus <mraghunandanan>/<peri123> <<eof Can anyone tell what is wrong... (3 Replies)
Discussion started by: mraghunandanan
3 Replies
Login or Register to Ask a Question