Solved

Run a batch script from webpage

Posted on 2013-11-07
17
314 Views
Last Modified: 2013-11-14
My webserver is a linux box.  There is a windows server on the same domain that holds a batch file.  Wondering if there is a way to have PHP connect to that server and run that batch file.

Would like to do this via a form which would run that batch file when the button is pressed.
0
Comment
Question by:t3chguy
  • 9
  • 7
17 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 39631528
That would be difficult.  To run a file on a different computer requires a login to that other computer.  And the user that PHP normally runs under on a web server is a very limited user that is not normally allowed outside of the web root.

You might be able to do it if you could work out all the problems with permissions and access.
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39631537
I have full access to both servers so I can do whatever I need to do.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39633273
Take a step back from the technical details and just give us the business rules.  What does the batch script do?  How is its output valuable?  If you can give us the larger picture, we may be able to suggest something that will get the results you need without any "hack."
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39633588
We have a rental management system that has a database back end, This batch file essentially connects to that database, pulls out the data via an ODBC connection, writes it to a table in access, then connects to my web server's database via an ODBC connection and compares the data and appends and updates when necessary.

This is essential to our business because it stores all of our company accounts that we need to access on our corporate intranet.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39633787
OK, it sounds like this is a data base synchronization question.  Couple of other questions, trying to get a sense of the flow of the data...

rental management system that has a database back end
What kind of data base is in play here?  Have you tried using PHP ODBC to connect directly to it?

writes it to a table in access
Microsoft Access?  

then connects to my web server's database
The batch file connects via ODBC?  What is the web server database?

accounts that we need to access on our corporate intranet.
Does the intranet use MS Access for its data base?
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39633946
The database of the result software is Progress.  My boss informs me that we can connect directly to it using ODBC.

Correct, Microsoft Access.

The batch file runs the script that essentially opens up Microsoft Access MDB file and runs the update query.

The intranet uses MySQL for it's database.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39634002
It seems to me that the whole process could be done with PHP, eliminating the need for the batch file.  If there isn't a show-stopper that I'm not seeing, that is the way I would go.
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39634303
Well, I found the show-stopper.

My server does not have ODBC and we let the licensing expire so I am unable to install anything, including ODBC.  We are getting new servers soon, which will fix the issue.  But until then, running that batch script is my only solution. :\
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:t3chguy
ID: 39634373
I found another server that I can use to connect:

Right now, I am getting the following error:

Notice: Undefined variable: portnumber in C:\wwwdocs\odbc.php on line 11 Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\wwwdocs\odbc.php on line 15 connection failed

$hostname = '192.168.0.99';
$portNumber = '1111';
$databaseName = 'dbname';
$username = 'user';
$password = 'pass';

$conn_string = "Driver={Progress OpenEdge 10.1C driver};
    HostName=" . $hostname . ";
    PortNumber=". $portnumber .";
    DatabaseName=" . $databaseName . ";
    DefaultIsolationLevel=READ UNCOMMITTED;";
       
$conn = odbc_connect($conn_string, $username, $password, SQL_CUR_USE_ODBC) or die("connection failed");

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39634390
PHP variable names are case-sensitive.  $portNumber != $portnumber
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39634423
Dumb mistake.  Still getting Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\wwwdocs\odbc.php on line 15 connection failed Though.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39634461
Line 15?  There are only 13 lines in the code snippet.  Maybe try adding in some error visualization, for example, print out the DSN and look to see if you can discern an error.
http://php.net/manual/en/function.odbc-connect.php
http://php.net/manual/en/function.odbc-error.php
http://php.net/manual/en/function.odbc-errormsg.php
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39639098
$hostname = '192.168.0.999';
$portnumber = '1111';
$databaseName = 'hr';
$username = 'userName';
$password = 'password';

$conn_string = "Driver={Progress OpenEdge 10.1C driver};
    HostName=" . $hostname . ";
    PortNumber=". $portnumber .";
    DatabaseName=" . $databaseName . ";
    DefaultIsolationLevel=READ UNCOMMITTED";
       
$conn = odbc_connect($conn_string, $username, $password, SQL_CUR_USE_ODBC) or die(odbc_errormsg());

if($conn)
	{
	echo 'Connection successful<br /><br />';

	$sql = "SELECT * FROM COGVIEWS_srnames";
			
	$res = odbc_exec($conn, $sql);

Open in new window


This returns an error stating:

Warning: odbc_exec(): SQL error: [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Table/View/Synonym not found (7519), SQL state S0002 in SQLExecDirect in C:\xampp\htdocs\odbc.php on line 21

No idea
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39639264
I think what it's saying is this:

Warning: odbc_exec(): SQL error: [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE] COGVIEWS_srnames not found (7519), SQL state S0002 in SQLExecDirect in C:\xampp\htdocs\odbc.php on line 21

In case it matters, the table names are almost certainly case-sensitive.
0
 
LVL 1

Author Comment

by:t3chguy
ID: 39639314
Unfortunately, that is the correct table name, with proper capitalization.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39639354
Do you have access to the SQL server so you can run commands directly (or some equivalent like phpMyAdmin)?  Maybe you can get the server to give you something?

About the only other thing I can think of is to ask the question over here.
0
 
LVL 1

Author Closing Comment

by:t3chguy
ID: 39647927
Great Solution, was able to plow my way through the rest of the script to get it fully working.

Thanks!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now