Sponsored Content
Top Forums Shell Programming and Scripting Bash script - ENV Variable context problem using su Post 302871083 by jcdole on Tuesday 5th of November 2013 12:48:01 PM
Old 11-05-2013
Quote:
Originally Posted by Chubler_XL
The exec su line is expanding your arguments. You could define CMDLN_ARGS like this:

Code:
CMDLN_ARGS="\"$@\"" # Command line arguments for this script

Does not help.

I have made some change. As the two executing jobs programs are very similar, I have made one program for the two task. So I am passing 3 arguments as I have added the copy direction ( "from" or "to" ).

So I am using now an unique program. And I get the same problem.

here is the command in the first launcher files_copy_from_server_launcher :
Code:
/home/user/bin/files_copy_server  "from"  "/root/bin/mysql*"  "/home/user/"

here is the command in the second launcher files_copy_to_server_launcher :
Code:
/home/user/bin/files_copy_server  "to" "/home/user/bin/files_copy*" "/root/bin/"

The first one run correctly.;
Here part of screen logs:


Code:
CMDLN_ARGS_2 :
Note : is blank in entry
CMD : /home/user/bin/files_copy_server PARAM : "from /root/bin/mysql* /home/user/" Please enter root's password. Password: CMDLN_ARGS_2 : "from /root/bin/mysql* /home/user/"
Note : is not blank because of the recursive call
Reading exec parameter $ 1 : from /root/bin/mysql* /home/user/
this is given by "echo $1"
$ 1 : from /root/bin/mysql* /home/user/
this is given by "echo "$1
$ { 1 } : from /root/bin/mysql* /home/user/
this is given by "echo ${1}"
$ { 1 } : from /root/bin/mysql* /home/user/
this is given by "echo "{$1}
MAIN - il y a 3 parametres MAIN - PARAM0 : /home/user/bin/files_copy_server MAIN - PARAM1 : from MAIN - PARAM2 : /root/bin/mysql* MAIN - PARAM3 : /home/user/

The second launcher run badly.;
Here part of screen logs; Note the important info for the following are in bold :

Code:
CMDLN_ARGS_2 :
Note : is blank in entry
CMD : /home/user/bin/files_copy_server PARAM : "to /home/user/bin/files_copy* /root/bin/" Please enter root's password. Password: CMDLN_ARGS_2 : "to /home/jcdole/bin/files_copy* /root/bin/"
Note : is not blank because of the recursive call
Reading exec parameter $ 1 : to /home/user/bin/files_copy* /root/bin/
this is given by "echo $1"
$ 1 : to /home/user/bin/files_copy_from_server /home/user/bin/files_copy_from_server.1 /home/user/bin/files_copy_from_server_launcher /home/user/bin/files_copy_from_server_launcher.1 /home/user/bin/files_copy_from_server_launcher.2 /home/user/bin/files_copy_from_server_launcher.3 /home/user/bin/files_copy_from_server_launcher.4 /home/user/bin/files_copy_server /home/user/bin/files_copy_server.1 /home/user/bin/files_copy_server.2 /home/user/bin/files_copy_server.3 /home/user/bin/files_copy_server.4 /home/user/bin/files_copy_to_server /home/user/bin/files_copy_to_server.1 /home/user/bin/files_copy_to_server.2 /home/user/bin/files_copy_to_server.3 /home/user/bin/files_copy_to_server.4 /home/user/bin/files_copy_to_server.5 /home/user/bin/files_copy_to_server_launcher /home/user/bin/files_copy_to_server_launcher.2 /home/user/bin/files_copy_to_server_launcher.3 /home/user/bin/files_copy_to_server_launcher.4 /root/bin/
this is bad this is given by "echo "$1
$ { 1 } : to /home/user/bin/files_copy* /root/bin/
this is given by "echo ${1}"
$ { 1 } : to /home/user/bin/files_copy_from_server /home/user/bin/files_copy_from_server.1 /home/user/bin/files_copy_from_server_launcher /home/user/bin/files_copy_from_server_launcher.1 /home/user/bin/files_copy_from_server_launcher.2 /home/user/bin/files_copy_from_server_launcher.3 /home/user/bin/files_copy_from_server_launcher.4 /home/user/bin/files_copy_server /home/user/bin/files_copy_server.1 /home/user/bin/files_copy_server.2 /home/user/bin/files_copy_server.3 /home/user/bin/files_copy_server.4 /home/user/bin/files_copy_to_server /home/user/bin/files_copy_to_server.1 /home/user/bin/files_copy_to_server.2 /home/user/bin/files_copy_to_server.3 /home/user/bin/files_copy_to_server.4 /home/user/bin/files_copy_to_server.5 /home/user/bin/files_copy_to_server_launcher /home/user/bin/files_copy_to_server_launcher.2 /home/user/bin/files_copy_to_server_launcher.3 /home/user/bin/files_copy_to_server_launcher.4 /root/bin/
this is bad this is given by "echo "${1}
MAIN - il y a 24 parametres this is bad MAIN - PARAM0 : /home/user/bin/files_copy_server MAIN - PARAM1 : to MAIN - PARAM2 : /home/user/bin/files_copy_from_server this is bad MAIN - PARAM3 : /home/user/bin/files_copy_from_server.1 this is bad

the program extract parameter in this loop :

Code:
for PARAM in $1 ; do
    case $MY_COUNT in
        0)
            DIRECTION=$PARAM
            ;;
        1)
            SOURCE=$PARAM
            ;;
        2)
            DESTINATION=$PARAM
            ;;
    esac
    ((MY_COUNT += 1 ))
done

As $1 is badly interpreted the program miss-function.

But why only in the second case in use. ?

Any help is welcome
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash env variable containing @

I want to set a bash env variable which has @ in its name, for example, @YOGESH@ may i know how do i do this? (4 Replies)
Discussion started by: Yogesh Sawant
4 Replies

2. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies

3. UNIX for Advanced & Expert Users

context lost problem

there are several same servers(process) on more than one server(machine) providing the same service. we store session/context within the server(process), if the same client login, he will be directed to the very server service for him last time. But, if a server(machine or process) down, the... (1 Reply)
Discussion started by: zhongyj
1 Replies

4. Shell Programming and Scripting

get env variable from last script

I have 2 scripts t2.sh calls t1.sh. I need to get the vaule of a env variable from t1.sh /tmp/test$ cat t1.sh #!/bin/sh INSTANCE="font/fc-cache" export INSTANCE svcadm disable ${INSTANCE} /tmp/test$ cat t2.sh #!/bin/sh . /tmp/test/t1.sh echo ${INSTANCE} The above works... (9 Replies)
Discussion started by: honglus
9 Replies

5. Shell Programming and Scripting

Set/Export Env Vars from with Shell Script With Input Variable

I have a shell script I want to run that will set environment variables based on the value of an input variable submitted when the shell script is called. For example: $ mgenv.sh prod This would set environment variables for prod $ mgenv.sh test This would set environment variables... (1 Reply)
Discussion started by: brtaylor73
1 Replies

6. UNIX for Advanced & Expert Users

problem in Unix Env. in Shell script

sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl os_lib-0.5.24;mbp os_lib-0.5.24; If i run this command in unix shell directly it is running. sdir;csp HA_util-0.0.7;bdir;cbpdob ---enable-useosstl HA_util-0.0.7;mbp HA_util-0.0.7; HA_util === Configuring source package HA_util... (4 Replies)
Discussion started by: girija
4 Replies

7. Shell Programming and Scripting

how to set/get shell env variable in python script

greetings, i have a sh script that calls a python script. the sh script sets an env variable BIN: export BIN=bin64i need to get that BIN variable's value and use it within this python script. anyone know how to do this? thanx in advance. (5 Replies)
Discussion started by: crimso
5 Replies

8. Web Development

Deny from env=env-variable Does not work

(Above from Apache docs). On my system, using: SetEnvIf User-Agent Mozilla IsBad=1 Order allow,deny Allow from all Deny from env=IsBad ...I see that environment variable is set (using phpinfo()) but the page is still served. No errors in the Apache logs. (1 Reply)
Discussion started by: gnurob
1 Replies

9. Shell Programming and Scripting

Bash, Dynamic Variable Problem >.<

Hello, I have a problem with a bash script, I've been doing recherches but i can't make it work. It is my first time with a dynamic variable and i don't understand how to write it. #!/bin/bash USER=BARSPIN HOTKEYS_PATH="/home/$USER/Documents/bash/tibia/HOTKEYS" CFG1="A" CFG2="B"... (5 Replies)
Discussion started by: barspin
5 Replies

10. Shell Programming and Scripting

BASH script to export var to env

Hi all I am trying to create a script that takes a password input then writes that to a tmp file and puts that tmp file path in my env as a var. It does everything but export the my env and I am unsure why. I am using Ubuntu 12.4 #!/bin/bash read -s -p "Enter Password: " gfpassword... (5 Replies)
Discussion started by: koikoi
5 Replies
All times are GMT -4. The time now is 09:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy