Running a shell script inside another shell script with another user

I have two shell scripts:

one.sh

echo "hello"
su - oracle -c "sh /tmp/two.sh" 
echo "good bye"

two.sh

echo "bla bla bla"

I want to run "one.sh" as "root" and see this output:

hello
bla bla bla
good bye

How is this possible?

+4
source share
2 answers

Install chmod +xon your scripts first

to try:

echo "hello"
su - oracle -c /tmp/two.sh
echo "good bye"
+1
source

In line

su - oracle -c "sh two.sh"

the interpreter does not know the path of the file "two.sh".

Try with an absolute path ... (e.g. sh / tmp / two.sh ").

So:

root@myServer:/tmp# ./one.sh
hello
bla bla bla
good bye

UPDATE

Please also check that "sh" can be found by oracle ... Otherwise, specify an absolute path for "sh", too ...

+2
source

Source: https://habr.com/ru/post/1527556/


All Articles