LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 01-28-2014, 02:33 AM   #1
PavanPatil
LQ Newbie
 
Registered: Jan 2014
Posts: 0

Rep: Reputation: Disabled
Help required for Running SQLPLUS command from Bat file


Hello All,

Good Afternoon.

I am new to this platform and I need one small help regarding running a SQL file from Bat file. Below is what I am doing,

1. I placed the below command in one Bat file.
start putty.exe -ssh user@host -pw pwd -m C:\2.txt

2. In 2.txt, I have below command.

sqlplus u/u@host @/root/home/sql1.sql

3. Sql1.sql has simple sql commands.

When I am invoking the bat file, its logging into putty and logging off and not doing any thing.

If I run separately 2.txt by logging into putty then its running properly.

Please help me out. If I posted wrongly then, please guide me.
 
Old 01-28-2014, 02:55 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@PavanPatil: You've posted your Windows related question on a Linux forum. That's not such a big problem (enough people here know something about Windows). I did ask a moderator to move this thread to the General section, this not being Linux related and all.
 
Old 01-28-2014, 02:57 AM   #3
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
Forget what I first wrote, I got the "putty" syntax wrong.

The "2.txt" file should contain commands as you would type them on the Linux system. Does the command
Code:
sqlplus u/u@host @/root/home/sql1.sql
in fact do what you want it to do?

Also, does the user account you specify with the "-ssh" switch have read access to the /home directory? (And why did you place the .sql file there in the first place? Wouldn't the home directory of the user you're connecting as be a better choice?)

Last edited by Ser Olmy; 01-28-2014 at 03:04 AM.
 
Old 01-28-2014, 04:51 AM   #4
PavanPatil
LQ Newbie
 
Registered: Jan 2014
Posts: 0

Original Poster
Rep: Reputation: Disabled
Hi Ser Olmy,

Thank you for reply.

Yes, command which I placed in the sql are proper. If I run this SQLPLUS command by directly login into PUTTY then, it works properly. Only the problem is if invoke the Putty from Bat file, then this SQLPLUS command wont work at all.

Sorry for posting path wrongly in my first post, I apologize for the same. The file is present in the Logged in USER folder only and user has all the necessary access to the folders.

Thanks.
 
Old 01-28-2014, 05:16 AM   #5
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
Quote:
Originally Posted by PavanPatil View Post
Yes, command which I placed in the sql are proper. If I run this SQLPLUS command by directly login into PUTTY then, it works properly. Only the problem is if invoke the Putty from Bat file, then this SQLPLUS command wont work at all.
When you say it "won't work", exactly what happens?

Does a "putty" window appear? If not, then perhaps the batch file can't find the putty.exe program file, and you need to specify the full path.

If a window does appear, does it connect? Do you get an error message?

If the window opens and closes too fast for you to see any messages, have you tried putting the command "pause" at the bottom of the batch file?

Have you tried removing "start", so the batch window remains until the putty.exe process exits?

The only error I can find, is in the "2.txt" file. There should be a "logout" command on the line below the sqlplus command, otherwise the ssh session will remain open. But the sqlplus command should still run.

Edit: Two more questions:
  • Where is the batch file located?
  • Where is putty.exe located?

Last edited by Ser Olmy; 01-28-2014 at 05:24 AM.
 
Old 01-28-2014, 05:30 AM   #6
PavanPatil
LQ Newbie
 
Registered: Jan 2014
Posts: 0

Original Poster
Rep: Reputation: Disabled
Hi Ser Olmy,

Putty opens and closes fast for me to see any message. I tried with Pause and its not waiting. It won't work means "What i want to achieve is not happening". If I try without sqlplus command like other MKDIR,CHMOD that file is also executing properly. Only file with SQLPLUS is failing to execute (It just runs without any error but not executing any commands). I assume its not working because from Bat file first I am referring 2.txt (by a path) then again I am accessing one more file (by a path).

Thanks for your help.

Best regards,
Pavan Patil
 
Old 01-28-2014, 05:39 AM   #7
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
For the batch file to work, it must be able to locate putty.exe. Unless putty.exe resides in a directory that's in the system search path, or you specify the full path in the batch file, it won't work. That's why I asked where you've saved putty.exe.
 
Old 01-28-2014, 05:57 AM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
There is one other possibility... Does SQL+ require a terminal to be attached? If it does, then directing putty to use a terminal even for commands that don't (such as running a command directly) might fix the problem.

This also occurs system-to-system with usage like "ssh user@host <commnds" because ssh will not use a terminal either.
 
Old 01-28-2014, 06:11 AM   #9
PavanPatil
LQ Newbie
 
Registered: Jan 2014
Posts: 0

Original Poster
Rep: Reputation: Disabled
Hi Ser Olmy,

I have placed putty in proper place only. Putty screen appears for me. I have one more similar situation where in one file I have only unix commands which running properly. Only this SQLPLUS is not happening.
 
Old 01-28-2014, 06:17 AM   #10
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
Quote:
Originally Posted by PavanPatil View Post
I have placed putty in proper place only.
And which place is that, exactly?

Quote:
Originally Posted by PavanPatil View Post
Putty screen appears for me.
You mean when you click on the executable?

Quote:
Originally Posted by PavanPatil View Post
I have one more similar situation where in one file I have only unix commands which running properly. Only this SQLPLUS is not happening.
And this other fil that runs Unix commands is similar, with the command(s) stored in a text file on the C: drive?

You said the batch file didn't stop even when you added a "pause" command. I'm sorry, but that just isn't possible, not if you edited the right file and added the "pause" command on a line by itself. "pause" always waits for [Enter] to be pressed.
 
Old 01-28-2014, 07:26 AM   #11
PavanPatil
LQ Newbie
 
Registered: Jan 2014
Posts: 0

Original Poster
Rep: Reputation: Disabled
Hi Ser Olmy,

Let me place the entire command here

Quote:
start C:\Software\Putty\putty.exe -ssh user@host -pw pwd -m C:\MyWork\2.txt
. When I run this Putty appear and shows me User then, logs in and then it will show some of the Putty Rights information and then disappear.

I don't see any error and with Pause one cmd.exe is getting opened along with the Putty.
 
Old 01-28-2014, 07:58 AM   #12
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
The "start" command means putty gets opened in a separate window.

I've just tried using putty to run commands on a Linux system in exactly the same way (specifying a user/hostname and password with the -ssh and -pw parameters and putting shell commands in a text file referenced by the -m parameter), and it worked just fine.

What do you mean by "putty rights information"?

Can the Windows computer resolve the computer name "host" (I realize that's not the actual name), or are you using an IP address in the "-ssh user@host" parameter?

If you leave out the "-m" parameter entirely, Putty should connect and log in, and give you a command prompt. Does that work?
 
Old 01-28-2014, 08:56 PM   #13
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I think SQLPLUS requires a terminal.

They way you are doing the ssh connection does not use a terminal.

Thus the SQLPLUS application will not start - it should be giving an error message which is likely being discarded.
 
Old 01-28-2014, 09:27 PM   #14
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
I think SQLPLUS requires a terminal.

They way you are doing the ssh connection does not use a terminal.
That does make sense, and would be consistent with what the OP is experiencing.

@PavanPatil: Try adding the "-t" option to the putty comamnd line, like this:
Code:
start C:\Software\Putty\putty.exe -ssh user@host -pw pwd -t -m C:\MyWork\2.txt
 
Old 01-28-2014, 10:25 PM   #15
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Definitely try that... When I gave a quick test to see what happens with a "echo tty | ssh -t localhost" I got logged in, but the server still didn't start a pseudoterminal (the output was "not a tty"). Now this COULD be a trait of ssh when stdin is not a terminal.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sqlplus connection help is required sushil_sk Linux - Newbie 1 11-29-2010 12:17 AM
running sqlscript outside the sqlplus wanghao Linux - Server 2 08-05-2008 12:22 AM
sqlplus command from script Grassie Coetzee LinuxQuestions.org Member Intro 2 03-13-2005 12:01 PM
Running SQLPLUS after installing Oracle 8i linux_pioneer Solaris / OpenSolaris 4 08-14-2004 11:59 PM
SQLplus command editor under UNIX - how?? stephstellar Programming 5 05-27-2003 08:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 01:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration