LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Issue with remote script execution (https://www.linuxquestions.org/questions/linux-newbie-8/issue-with-remote-script-execution-878590/)

Orange Sunshine 05-03-2011 12:06 PM

Issue with remote script execution
 
I have a very simple script that creates another script that I want to copy over to my oracle server (on a separate machine from my resin server) and then execute. It looks like this:
Code:

#!/bin/bash
echo "#!/bin/bash

/path/to/sqlplus -s /nolog <<EOF
connect username/password
@file1.sql
@file2.sql
@file3.sql
@file4.sql
EOF" > /home/user/trythis.sh

scp /home/user/trythis.sh oracle@11.1.11.111:/tmp/script
ssh oracle@11.1.11.111 bash /tmp/script/trythis.sh

The new script (trythis.sh) creates and copies over to the oracle server fine. I can even log into the oracle server and execute the script and it executes completely without issue. The problem is when I try to execute the script from my resin machine (either within the original script or just from the regular prompt). I type:

ssh oracle@11.1.11.111 bash /tmp/script/trythis.sh

and I get:

Error 6 initializing SQL*Plus
Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

Any ideas? I'm pretty sure ORACLE_HOME is set on my oracle machine because, as I said, I can execute the exact same script fine when logged into my oracle machine. I read something about sourcing the bash profile but I couldn't figure out the details of what was being talked about and I also didn't know if it was relevant to my issue (came up when I searched for the error I was getting).

rylan76 05-03-2011 02:40 PM

Quote:

ssh oracle@11.1.11.111 bash /tmp/script/trythis.sh

and I get:

Error 6 initializing SQL*Plus
Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
Bit of a shot in the dark, but what usergroup / user does that file (erm... probably sp1_en.msb??) belong to?

E. g. it looks like your script is starting up, but the user it is running as does not have permission to access some of the files the script (or binaries it starts up) need to be able to read to run.

I'd try finding that file with something like (as root):

Code:

find / -name sp1_en.msb
and then checking its permissions. Maybe if you can find this file you can try changing its permissions to be, for example, world readable and see if that changes anything??

Orange Sunshine 05-03-2011 03:01 PM

Quote:

Originally Posted by rylan76 (Post 4345395)
Bit of a shot in the dark, but what usergroup / user does that file (erm... probably sp1_en.msb??) belong to?

E. g. it looks like your script is starting up, but the user it is running as does not have permission to access some of the files the script (or binaries it starts up) need to be able to read to run.

I'd try finding that file with something like (as root):

Code:

find / -name sp1_en.msb
and then checking its permissions. Maybe if you can find this file you can try changing its permissions to be, for example, world readable and see if that changes anything??

Interesting...when I do what you said I get this:

Code:

-bash-3.00$ find / -name sp1_en.msb
find: /root: Permission denied
find: /home/postgres: Permission denied
find: /home/nbbs: Permission denied
find: /var/gdm: Permission denied
find: /var/cache/samba/winbindd_privileged: Permission denied
find: /var/cache/alchemist/printconf.rpm/wm: Permission denied
find: /var/cache/alchemist/printconf.local/wm: Permission denied
find: /var/cache/mod_proxy: Permission denied
find: /var/log/samba: Permission denied
find: /var/log/ppp: Permission denied
find: /var/log/httpd: Permission denied
find: /var/log/audit: Permission denied
find: /var/empty/sshd: Permission denied
find: /var/lib/php/session: Permission denied
find: /var/lib/slocate: Permission denied
find: /var/lib/pgsql: Permission denied
find: /var/lib/dav: Permission denied
find: /var/lib/nfs/statd: Permission denied
find: /var/lib/dhcpv6: Permission denied
find: /var/run/mdmpd: Permission denied
find: /var/run/mdadm: Permission denied
find: /var/run/sudo: Permission denied
find: /var/run/usb: Permission denied
find: /var/net-snmp: Permission denied
find: /var/lock/lvm: Permission denied
find: /var/spool/at: Permission denied
find: /var/spool/cups: Permission denied
find: /var/spool/clientmqueue: Permission denied
find: /var/spool/cron: Permission denied
find: /var/spool/mqueue: Permission denied
find: /usr/share/ssl/CA: Permission denied
find: /usr/local/u01/app/pgsql/data: Permission denied
find: /boot/lost+found: Permission denied
find: /etc/racoon/certs: Permission denied
find: /etc/cups/certs: Permission denied
find: /lost+found: Permission denied
find: /mnt/disk3/lost+found: Permission denied
find: /mnt/disk4/lost+found: Permission denied
find: /mnt/disk2/lost+found: Permission denied
find: /proc/tty/driver: Permission denied
find: /proc/1/task/1/fd: Permission denied
find: /proc/2/task/2/fd: Permission denied
find: /proc/3/task/3/fd: Permission denied
find: /proc/4/task/4/fd: Permission denied
find: /proc/5/task/5/fd: Permission denied
find: /proc/6/task/6/fd: Permission denied
find: /proc/7/task/7/fd: Permission denied
find: /proc/8/task/8/fd: Permission denied
find: /proc/9/task/9/fd: Permission denied
find: /proc/37/task/37/fd: Permission denied
find: /proc/38/task/38/fd: Permission denied
find: /proc/48/task/48/fd: Permission denied
find: /proc/51/task/51/fd: Permission denied
find: /proc/52/task/52/fd: Permission denied
find: /proc/39/task/39/fd: Permission denied
find: /proc/50/task/50/fd: Permission denied
find: /proc/125/task/125/fd: Permission denied
find: /proc/205/task/205/fd: Permission denied
find: /proc/206/task/206/fd: Permission denied
find: /proc/210/task/210/fd: Permission denied
find: /proc/211/task/211/fd: Permission denied
find: /proc/231/task/231/fd: Permission denied
find: /proc/678/task/678/fd: Permission denied
find: /proc/1180/task/1180/fd: Permission denied
find: /proc/1801/task/1801/fd: Permission denied
find: /proc/1802/task/1802/fd: Permission denied
find: /proc/1822/task/1822/fd: Permission denied
find: /proc/1823/task/1823/fd: Permission denied
find: /proc/1824/task/1824/fd: Permission denied
find: /proc/1825/task/1825/fd: Permission denied
find: /proc/2361/task/2361/fd: Permission denied
find: /proc/2365/task/2365/fd: Permission denied
find: /proc/2376/task/2376/fd: Permission denied
find: /proc/2388/task/2388/fd: Permission denied
find: /proc/2409/task/2409/fd: Permission denied
find: /proc/2439/task/2439/fd: Permission denied
find: /proc/2530/task/2530/fd: Permission denied
find: /proc/2585/task/2585/fd: Permission denied
find: /proc/2600/task/2600/fd: Permission denied
find: /proc/2616/task/2616/fd: Permission denied
find: /proc/2659/task/2659/fd: Permission denied
find: /proc/2661/task/2661/fd: Permission denied
find: /proc/2663/task/2663/fd: Permission denied
find: /proc/2664/task/2664/fd: Permission denied
find: /proc/2686/task/2686/fd: Permission denied
find: /proc/2694/task/2694/fd: Permission denied
find: /proc/2705/task/2705/fd: Permission denied
find: /proc/2715/task/2715/fd: Permission denied
find: /proc/2738/task/2738/fd: Permission denied
find: /proc/2757/task/2757/fd: Permission denied
find: /proc/2776/task/2776/fd: Permission denied
find: /proc/2786/task/2786/fd: Permission denied
find: /proc/2797/task/2797/fd: Permission denied
find: /proc/2807/task/2807/fd: Permission denied
find: /proc/2808/task/2808/fd: Permission denied
find: /proc/2809/task/2809/fd: Permission denied
find: /proc/2812/task/2812/fd: Permission denied
find: /proc/2817/task/2817/fd: Permission denied
find: /proc/2820/task/2820/fd: Permission denied
find: /proc/2836/task/2836/fd: Permission denied
find: /proc/3086/task/3086/fd: Permission denied
find: /proc/3091/task/3091/fd: Permission denied
find: /proc/3520/task/3520/fd: Permission denied
find: /proc/5314/task/5314/fd: Permission denied
find: /proc/23168/task/23168/fd: Permission denied
find: /proc/11201/task/11201/fd: Permission denied
find: /proc/11203/task/11203/fd: Permission denied
-bash-3.00$

So how to I even start with finding which file I need to change the permissions of? Also, when I just run the script from the oracle machine (instead of remotely) I am logged in as user 'oracle' and it runs fine. So does it make sense that I would have permission problems when I ssh into the machine as the same user 'oracle'? I'm stumped.

chrism01 05-03-2011 06:12 PM

1. you prob don't need to change perms on the msb file, but fyi, when running find across the whole system, re-direct errors to null eg

Code:

find / -name sp1_en.msb 2>/dev/null
2. you can src the ORACLE env setup in you script, you just have to know where it's set eg
Code:

#!/bin/bash
echo "#!/bin/bash  # why are you doing this ???

. /home/oracle/.bashrc

/path/to/sqlplus -s /nolog <<EOF
.
.
.


Orange Sunshine 05-03-2011 10:36 PM

Quote:

Originally Posted by chrism01 (Post 4345595)
Code:

#!/bin/bash
echo "#!/bin/bash  # why are you doing this ???


I'm doing that because my main script is creating another script that's copied over to the Oracle machine. The beginning of the script being created is "#!/bin/bash" just like the beginning of my main script. Is this not correct?

As far as the ORACLE env variable thing goes... I'm a little confused. The ORACLE_HOME variable IS set on the oracle machine and as I said, the script that's copied over executes fine on the oracle machine. That being said, I did source the ORACLE environment as you suggested and I still get the same error.

The other way I tried first was just running each sql command individually via ssh within the main script, example:

Code:

ssh oracle@11.1.11.111 path/to/sqlplus user/pass @/path/to/sql/script/on/oracle/machine.sql
ssh oracle@11.1.11.111 path/to/sqlplus user/pass @/path/to/another/script.sql
.
.
.

...that effort resulted in the same error:

Error 6 initializing SQL*Plus
Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

I think I've ruled out the ORACLE_HOME set issue but I'm open to suggestions.

Any other reason you guys can think of that the script would execute fine on the oracle box but not via ssh from my resin box? OR, any suggestions as to how I can do something similar in another way?

Orange Sunshine 05-05-2011 03:03 PM

Well, I've been at this issue for 2 solid days now and am not getting anywhere. Does anyone know what the issue could be or have a better way for me to execute the sqlplus scripts from my resin machine (where no oracle instance is installed)?

rylan76 05-09-2011 04:48 AM

[QUOTE=Orange Sunshine;4345414]Interesting...when I do what you said I get this:

Code:

-bash-3.00$ find / -name sp1_en.msb
find: /root: Permission denied
find: /home/postgres: Permission denied
find: /home/nbbs: Permission denied
<snip>
-bash-3.00$

My bad. You need to become root before you do that find / -name sp1_en.msb command...

Quote:

So how to I even start with finding which file I need to change the permissions of? Also, when I just run the script from the oracle machine (instead of remotely) I am logged in as user 'oracle' and it runs fine. So does it make sense that I would have permission problems when I ssh into the machine as the same user 'oracle'? I'm stumped.
You might. I once had this same situation with an old SCO / Unix system I had to get into. On the machine itself, no problem logging in directly as a bash user and doing things. However, if I came in over SSH (or even telnet) it somehow "knew" I wasn't on that machine - I could still get in as the user I used physically on it, but my permissions where restricted. Not sure (to this day - it was years ago) just how it detected that...

rylan76 05-09-2011 04:54 AM

Quote:

Originally Posted by Orange Sunshine (Post 4345779)
Any other reason you guys can think of that the script would execute fine on the oracle box but not via ssh from my resin box? OR, any suggestions as to how I can do something similar in another way?

Well, not sure if it will work for your situation and requirements, but how about starting the script locally, not remotely?

E. g. you still go ahead and copy your script over as required. However, you do NOT start it from your remote connection. How about setting up a script on the target machine, that is run by cron locally on that machine, that starts your script?

E. g. setup a cron that runs each five minutes. All it does is call your script that has been copied in whenever like you detail in your above messages. This way, from everything on the target machine's viewpoint, the script starts up LOCALLY, via cron, so it should have all the permissions it needs? Just write the cron script locally "as" the user which runs Oracle.

You can then add refinements such as having the cronned script just die quietly if your "command script" is not present in a certain folder. This way you can precisely control when and what is executed, simply by copying over the script, leaving for at least 6 minutes (thus ensuring execution somewhere in that time window, by cron, of the script) and then deleting it remotely?

You can do all this quite easily with PHP for example, as regards making an FTP connection to copy the file to a certain location, then deleting it after a time delay... you can even farm that time delay functionality out to the cron on your remote system?

The idea of course being to NOT try to run the script remotely, but having it run locally as the correct user Oracle runs as anyway. This should short-circuit any permission complaints, I hope...


All times are GMT -5. The time now is 06:40 PM.