Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

Run a batch script from webpage

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
t3chguy
Asked:
t3chguy
  • 9
  • 7
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
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
 
t3chguyAuthor Commented:
I have full access to both servers so I can do whatever I need to do.
0
 
Ray PaseurCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
t3chguyAuthor Commented:
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
 
Ray PaseurCommented:
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
 
t3chguyAuthor Commented:
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
 
Ray PaseurCommented:
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
 
t3chguyAuthor Commented:
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
 
t3chguyAuthor Commented:
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
 
Ray PaseurCommented:
PHP variable names are case-sensitive.  $portNumber != $portnumber
0
 
t3chguyAuthor Commented:
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
 
Ray PaseurCommented:
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
 
t3chguyAuthor Commented:
$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
 
Ray PaseurCommented:
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
 
t3chguyAuthor Commented:
Unfortunately, that is the correct table name, with proper capitalization.
0
 
Ray PaseurCommented:
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
 
t3chguyAuthor Commented:
Great Solution, was able to plow my way through the rest of the script to get it fully working.

Thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now