SU within a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SU within a script
# 1  
Old 02-09-2007
Question SU within a script

Hi There,

I'm trying to get a script to su to a user and then run a following script but all it seems to do is su to a new users within a new shell and then run the commands after in the old shell.

Is there a way to su and then get the user to run the commands?

Cheers
Kees
# 2  
Old 02-09-2007
Instead of:

su [-] someuser
newscript.sh

use:

su [-] someuser -c newscript.sh

Whether you put a "-" between "sU" and "someuser" depends on whose environment you want to use when executing the script "newscript.sh".

If you use:
su - newuser -c newscript.sh
the environment settings of "newuser" will be used.

If you use:
su newuser -c newscript.sh
your own environment settings will be used.
# 3  
Old 02-13-2007
Thanks, can I ask what the -c does?
# 4  
Old 02-13-2007
Quote:
Originally Posted by KeesH
Thanks, can I ask what the -c does?

passing a single command to the shell

Code:
man su

# 5  
Old 02-13-2007
Here are my two scripts, I want the first one to change to eupuk and then run the second one, but it doesn't seem to work.

kees.sh
su - eupuk -c /backup/ops/HSBC_file_transfer.sh

HSBC_file_transfer.sh
#!/bin/ksh

#ln -s /cer_eupuk/exe/ABS_LOGICALS ABS_LOGICALS
#. /cerillion_homes/euphony/users/tes01/.profile
# User Variables
FILEPATH=/cer_testgmt/work/par/hoca
FILENAME=HSBC_LO*
FINANCESCRIPT=/cer_testgmt/exe/par60105b_auto.sh
cd $FILEPATH
cp HSBC* /cer_testgmt/work/par/hoca/tmp

if [ -f $FILENAME ]
then
$FINANCESCRIPT
fi

I Get the following when I run it.


cp: /cer_testgmt/work/par/hoca/tmp/HSBC_HOCA05022007.txt: The file access permissions do not allow the specified action.
cp: /cer_testgmt/work/par/hoca/tmp/HSBC_HOCAEXP05022007.txt: The file access permissions do not allow the specified action.
cp: /cer_testgmt/work/par/hoca/tmp/HSBC_LOCKBOX05022007.txt: The file access permissions do not allow the specified action.
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : Starting
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : Logging to '/cer_testgmt/log/par60105b_auto_2515042_2433060.log'
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : ORACLE_SID = ''
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : ORACLE_LOGON = ''
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : ORACLE_HOME = ''
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : One or more Oracle environment variables not set

Can anyone shed any light please?? Smilie
# 6  
Old 02-13-2007
Quote:
Originally Posted by KeesH

I Get the following when I run it.


cp: /cer_testgmt/work/par/hoca/tmp/HSBC_HOCA05022007.txt: The file access permissions do not allow the specified action.
cp: /cer_testgmt/work/par/hoca/tmp/HSBC_HOCAEXP05022007.txt: The file access permissions do not allow the specified action.
cp: /cer_testgmt/work/par/hoca/tmp/HSBC_LOCKBOX05022007.txt: The file access permissions do not allow the specified action.
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : Starting
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : Logging to '/cer_testgmt/log/par60105b_auto_2515042_2433060.log'
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : ORACLE_SID = ''
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : ORACLE_LOGON = ''
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : ORACLE_HOME = ''
/cer_testgmt/exe/par60105b_auto.sh: 2007_02_13 08:15:19 : One or more Oracle environment variables not set

Can anyone shed any light please?? Smilie
It's clear to me, the o/p is already telling you... Two "errors":
- Permissions: The user has no righs to do that copy. Just chmod those files. Take into account that the user eupuk must have rights to do those cps.
- Environment: Oracle variables not set for the user. Just set them on HSBC_file_transfer.sh.

Regards.
Just read the messages.
# 7  
Old 02-13-2007
I've sorted out the file permissions error, that was a mistake by me.

But with the oracle env settings, that user that i've su'd to has them already set, why is it not picking them up?
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question