Bash script - ENV Variable context problem using su
Hello
I have found some piece of code to verify and then run shell script with root permission from normal user.
see : http://blog.mecworks.com/articles/20...script-as-root
I have wrote two scripts using this tips.
- one to copy file from server to local computer ( files_copy_from_server.sh )
and this program is started by using another script ( files_copy_from_server_launcher.sh)
- one to copy file to server from local computer ( files_copy_to_server.sh )
and this program is started by using another script ( files_copy_to_server_launcher.sh)
The first one run perfectly.
The second one failed because variables are not set correctly :
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 :
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 :
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.
I suspect that /root/bin/mysql* currently doesn't match any files so the shell is leaving it unexpanded whereas /home/user/bin/files_copy* does match files.
[SOLVED]Bash script - ENV Variable context problem using su Edit Post
Quote:
Originally Posted by Chubler_XL
I suspect that /root/bin/mysql* currently doesn't match any files so the shell is leaving it unexpanded whereas /home/user/bin/files_copy* does match files.
Yes that's the reason.
Got it to work with the use of : set -f before the expansion of CMDLN_ARGS
Code:
set -f
for PARAM in $1 ;
do case $MY_COUNT in
0) DIRECTION=$PARAM ;;
1) SOURCE=$PARAM ;;
2) DESTINATION=$PARAM ;;
esac ((MY_COUNT += 1 )) done
set +f
Last edited by jcdole; 11-11-2013 at 07:21 PM..
Reason: solved
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)
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)
(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)
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)
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)
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)
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)
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)
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)