Running remote shell script containing sql statements


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running remote shell script containing sql statements
# 1  
Old 12-27-2001
Running remote shell script containing sql statements

I have a shell script which resides on three SCO machines containing some simple sqlplus statments. I need to run these scripts remotely. Currently, I am trying to use rsh to do so:

rsh hostname myscript args

The problem is that the arguments to the sqlplus statements in the remote shell scripts are unrecognized. If I run the scripts from the command line of their respective machines, everything works fine. So, it looks like an rsh issue. Here is some more specific information:

I am running rsh as follows:

rsh raptor bin/my_script Y Y Y Y

where the Ys are the args to my_script. my_script contains the following:

#!/usr/bin/ksh

which_sql=`whence sqlplus`

$which_sql -s sti/sti <<EOF
set heading off
set pause off
update my_table
set HOST_ON_DUTY = '$1',
EXPRESS_SHIPPING = '$2',
INTERNATIONAL_ORDERS= '$3',
COD = '$4';
exit
EOF

..and the error I'm getting back is:

bin/my_script: line 5: -s: not found

..I am guessing that the flags to the sql statement are being interpreted locally instead of remotely.

Any help would be greatly appreciated!
# 2  
Old 12-28-2001
rsh does not execute your .profile (same as ftp), so your environment is not getting established like it would on a true login to that server. With ORACLE_HOME/bin not in your PATH, the whence is coming up null. Since $which_sql is null, the first thing on the command line is the -s.

First thing in my_script should be to source your environment so that sqlplus is in your PATH.
Jimbo
# 3  
Old 01-03-2002
I suggest you to create a remote shell script. I'm not use RSH anymore since it's not a secure connection type.



Like Jimbo, i suggest you to define the environtment first, for example:

-------------------------------------

#!/bin/sh

PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin

... your shell code here.

-------------------------------------
# 4  
Old 05-16-2006
write you script and test on the remote host.

copy your script to home.
when your are on your home again use:
cat myscript.sh | ssh remote "/bin/bash -s"

'bash -s' takes stdin as input (here the pipe), geuss ksh knows something like that. you earn extra bonus points by using reocde in cases when the charset on home and remote are different.
# 5  
Old 05-16-2006
This type of stuff seems to just keep coming back. People want to run scripts remotely. I've tried every way I can think of and this is the best way. You not only get functionality but you get security as well. Every Unix environment needs a way to issue shell scripts, perl script, SQL scripts to remote servers. I have posted the following example already but I will do it again. Everytime I go to a new company the first thing I do is build an issuance process. A way to issue script remotely outside of using some scheduler like Maestro or Control -m.





This is really a multi step process. You need to setup SSH correctly and create a key pair and passphrase. Then you need to load your keys into the SSH agent so that you don't get prompted for a passphrase. The SSH agent will handle passing your passphrase to the other systems.

Example:

#ssh-add
Adding identity: /home/tester/.ssh2/id_dsa_1024_defender.pub
Need passphrase for /home/tester/.ssh2/id_dsa_1024_defender.pub
(1024-bit dsa, tester@defender, Sun Apr 30 2000 21:39:13).
Enter passphrase:

#ssh server date
Wed May 10 14:06:57 EDT 2006
#

#Now that you have SSH setup. You can take any script and scp the script to the remote server.



Sample script below
###############################################
#!/bin/sh

LOG="/tmp/MYTEST.log
##################
function if_error
##################
{
if [[ $? -ne 0 ]]; then # check return code passed to function
print "$1 TIME:$TIME" | tee -a $LOG # if rc > 0 then print error msg and quit
exit $?
fi
}

chown root:root /etc/passwd
if_error "Failed chowning /etc/passwd to root:root"

chmod 700 /etc/passwd
if_error "Failed chmoding /etc/passwd to 700"

rm -rf /etc/somedir
if_error "Failed deleting /etc/somedir"
################################################

#Okay..So SSH is working and you got a little test script with the proper error checking in it. Also, I used the tee command to redirect the output of the script to the screen and to a log file in tmp.

scp $USER@$HOST:$PATH/$SCRIPT $USER@$HOST:/tmp/$SCRIPT
ssh -l $USER $HOST chmod 700 /tmp/$SCRIPT
ssh -l $USER $HOST /tmp/$SCRIPT
ssh -l $USER HOST rm /tmp/$SCRIPT

1. Copied script to server
2. Changed permissions
3. Executed script that will write to log file and screen cause I wrote it like that.
4. rm the script


Hope this is helpful.

-X
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running set of commands in remote servers in shell script

Hi Wishing to all. I am very new joined in an organization as a unix system administrator. I need a help in preparing a script for a report. i have a file contains all of the linux/ubuntu servers line by line around 140 servers. vi servers.txt nh01 nh02 nh03 bh01 bh04 - - :wq (3 Replies)
Discussion started by: kumaraswamy
3 Replies

2. OS X (Apple)

Quit a shell script thats running on a remote machine

I'm in a situation where I am executing a shell script(Bash) on another machine remotely using ssh, and for various reasons sometimes need to quit it and restart it. The shell script being run does many different things, so its hard to know what process to kill on the remote machine, and even if I... (2 Replies)
Discussion started by: TheDrizzle
2 Replies

3. UNIX for Dummies Questions & Answers

SQL block in a Shell Script connecting to a local and remote DB

Hi All, In a Shell scriipt with a SQL block I want to issue a query against a local DB and a remote DB on a remote server. The shell script is running locally. This is how I connect to the local server. But I want the query to reference remote table in the join. Question can I specify a... (1 Reply)
Discussion started by: daveu7
1 Replies

4. Shell Programming and Scripting

Running remote system shell script and c binary file from windows machine using java

Hi, I have an shell script program in a remote linux machine which will do some specific monitoring functionality. Also, have some C executables in that machine. From a windows machine, I want to run the shell script program (If possible using java). I tried with SSH for this. but, in... (1 Reply)
Discussion started by: ram.sj
1 Replies

5. Shell Programming and Scripting

Running Oracle SQL from shell script

Hi, can anyone help me with this script please. I need the oracle command to go into the unix batch file. #!/bin/sh # A menu driven Shell script which has following options # for acmtoron@> # # # Exit # As per option do the job #---- while : do clear echo " A C M LOG MONITORING... (0 Replies)
Discussion started by: tinaaguilera
0 Replies

6. Shell Programming and Scripting

Looping through a shell script with sql statements

Hello members, I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting; Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a... (4 Replies)
Discussion started by: novice82
4 Replies

7. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies

8. UNIX for Dummies Questions & Answers

Running file sql from shell without capture the password

Dear All I have file a.sql, let's say the content is: _________________________________ select * from dual; exit; _________________________________ and I have shell script a.sh, the content is: _________________________________ ORACLE_SID=testing; export ORACLE_SID... (0 Replies)
Discussion started by: Aditya Purwanto
0 Replies

9. UNIX for Dummies Questions & Answers

Sh Shell Script executing remote SQL queries

Hi there folks, I am trying to execute remote sql queries on an Oracle server. I would like to save the result of the executed sql queries on a text file, and send that text file as an attachment to an email address. Could anyone give me an idea on how the above could be achieved? Any help... (2 Replies)
Discussion started by: Javed
2 Replies

10. Shell Programming and Scripting

Running SQL Scripts from Shell script - Need insight!

I've a script that fetches various values from the database as below: #! /bin/ksh $conn="user/pwd@service_name" `sqlplus -s << $conn EOF1 @xyz.sql @pqr.sql @abc.sql EOF1` The output of the script should generate txt files containing the results from queries which are further... (6 Replies)
Discussion started by: manthasirisha
6 Replies
Login or Register to Ask a Question