Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

run bash scripts with php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

run bash scripts with php

Postby penguino » Tue Oct 30, 2012 3:54 am

hello, i would lilke to create a page with links that will run sh files (bash scripts), for personal use.
I have installed lampp on my linux machine and able to run php files on it.
I'm not familiar with php and had no luck so far with getting it done.

Thank you.
penguino
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Oct 29, 2012 9:42 am

so this is what i made with no luck

Postby penguino » Tue Oct 30, 2012 4:11 am

An html file to run the php in a link

Code: Select all
<html>
<title></title>

<a href="2.php">run tmp.sh</a>

</html>


and the php file

Code: Select all
<?
exec('sh tmp.sh');
?>


and finally the sh file which just prints out a line in the terminal.

But nothing happens when i press on the link
penguino
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Oct 29, 2012 9:42 am

Re: run bash scripts with php

Postby jinijames » Tue Oct 30, 2012 4:43 am

#!/bin/sh

/usr/bin/php test.php
wait

/bin/bash test.sh
wait

/usr/bin/php test2.php
wait

/bin/bash test2.sh
wait

echo all done



hire php developer | hire magento developer
jinijames
New php-forum User
New php-forum User
 
Posts: 20
Joined: Fri Oct 19, 2012 4:32 am
Location: India

Re: run bash scripts with php

Postby penguino » Tue Oct 30, 2012 5:35 am

thank you for the reply, however i'm not sure i got this..

do i need to copy the sh file to the /bin/bash folder for it to run through the php?
and why what you wrote has to run two php files?
penguino
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Oct 29, 2012 9:42 am

Re: run bash scripts with php

Postby penguino » Tue Oct 30, 2012 7:33 am

Still trying unsuccessfully... anyone?
penguino
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Oct 29, 2012 9:42 am

Re: run bash scripts with php

Postby penguino » Tue Oct 30, 2012 1:00 pm

i got it to run the sh file and commands like echo runs ok, however background processes and programs can't be run and gives: "cannot open display" error..
penguino
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Oct 29, 2012 9:42 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.