Switching user inside a shell script doesn't seem to work
Linux version : Oracle Linux 6.4
Shell : Bash
The following script will be run as root. During the execution, it should switch to oracle user and execute few commands.
After googling and searching within unix.com , I came up with the following syntax
## Enclosing all commands in double quotes with the following syntax
## Using single quote like below didn't work for me
So, I created the following simple script called test.sh and executed it.
But it seems that the switch user using su didn't work properly.
/tmp/who.txt file shows root. It should show orace user if su worked properly.
/tmp/MYVAR2.txt is empty . It should show Duffy
/tmp/Instancename.txt is empty. It should show JUMBO1
-- Executing the script
--- Verifying the content of the files
Because of the use of double quotes, echo `whoami` gets executed before the su - l takes place. What did not work for you, when you were using single quotes?
This User Gave Thanks to Scrutinizer For This Post:
I tried enclosing in single quotes. But it doesn't work properly. Any Idea how I can fix this ?
--- Executing the script
#
-- Verifying the contents of files
# cat /tmp/ORACLE_SID_VAR
1 ---------------------> I am expecting SOFIA1
#
# cat /tmp/who.txt
oracle ---------------------> Worked as expected
#
# cat /tmp/Arg_name.txt
----------------------> null. I was expecting SOFIA
#
# cat /tmp/MYVAR2.txt
Duffy ---------------------> Worked as expected
#
Hello
I have a shell script that is run as root. Script rins ok until the point where it have to switch to user "mqm" to run other commands. It just hangs at the point of this line in the script
su - mqm -c "dspmq"
I ran the same commands at the terminal and they run fine.
Any thoughts. (6 Replies)
hi,
i want to login as a different user inside a shell script and then call another shell script from that script.
how to do that?
original script : script_A.sh
so when the script_A.sh is called , i want to login as a different user and then call another shell script(script_B.sh) from... (3 Replies)
Hello all,
Something strange going on with a shell script I'm writing. It's trying to write a list of files that it finds in a given directory to another file. But I also have a skip list so matching files that are in that skip list should be, well uhm, skipped :)
Here's the code of my... (2 Replies)
I am writing perl script to configure Cisco device but Variables inside Net::Telnet::Cisco Module doesn't work and passed to device without resolving.
Please advise.
here is a sample of script:
use Net::Telnet::Cisco;
$device = "10.14.199.1";
($o1, $o2, $o3, $o4) = split(/\./,$device);... (5 Replies)
Hi folks
I'm coding on Ubuntu 9.04 standard shell.
I'm writing a script that needs to generate a random number at some point of its execution.
When I do
echo $RANDOMas a command inside shell, I clearly get some randomly generated number
However when I do
i=`$RANDOM`
echo $ior even... (14 Replies)
Dear All,
I want to switch a user inside a shell script.My current user say x and user y to whom i want to switch both have login on the same server,the one on which i want to execute my script on.
"I want to do something like this
su - y
Password should be provided in the script itself.And... (6 Replies)
Hi,
I have a shell script in which I need to switch to another user and execute some commands and then come back to the original user.
To make it more clear -
I have to log in as user root then 'su' to jag - execute a script called backup.sh and then logout and come back to root again..
... (1 Reply)
Howdie everyone...
I have a shell script RemoveFiles.sh
Inside this file, it only has two commands as below:
rm -f ../../reportToday/temp/*
rm -f ../../report/*
My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
I am trying to run the following code from a script file but it complains that syntax of (both instances of) grep is wrong.
When I copy and paste it to the terminal, it is OK. Any idea what the problem might be?
set i = `grep -c #define flags.h`
while ($i>20)
@ i--
my func (`cat... (4 Replies)