Using PHP, run bash script and see results on Server's Monitor
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Using PHP, run bash script and see results on Server's Monitor
Hello, I'm making a digital picture frame out of an old laptop and I'm setting up Gallery (a php photo gallery organizer) so that I can manage the photos via a nice web interface. I want to add a few links to the php site so that you can start/stop/turnoff/etc the picture frame.
How do I run those already configured scripts that lie on the server?
As far as I know, php can only send output to one interface at a time. However, you can shell to an external program (which can even be a php script if your system is configured to run php scripts from the command line and php is in the path... This is very confusing and nobody does it that way.)
Your laptop "server" should already be set u to allow the exec family of functions, configured in php.ini but it might conceivably be disabled on some systems.
There are lots of ways to do this. You can, for example, write a copy of the album and then exec ('htmlview file://album.php'); to cause a web page to pop up that file on the server's screen... Or you could make it an auto-refreshing page and simply update it now and then... Or you could put the contents in a database and updated the database. Same effect.
I did something similar on my site, only I have it where visitors can draw a picture using javascript, which is saved in a database. From there the image data is sent via serial cable and displayed on an electronic sign for all to see. Naturally, some people will draw dirty pictures but the detail is not that great.
I guess, more or less, it's not really a php script that will run serverside, it's just a link on the php page that when clicked will run a bash script (or something similar) on the server. I'd be able to reboot the server, shutdown, and do lots of things via this function, even open a firefox browser on the server (which is logged in as one of its users and running X)
-I think you have the idea, but what would I do to run my ".sh" script for example?
Well, sort of. You see, i'm giving this as a gift to my parents and they don't know too much about computers, so I want to just have a page they can open (maybe type in a user and pass) and then be able to do a few simple tasks such as start a slideshow on the digital picture frame (there will be multiple slideshows they can run). Or let them run my little script that turns on/off the lcd (not shutdown/standby), or similar stuff like that.
I want to have like 3-4 tasks/scripts they can just click on and have the server run those processes/scripts. No interface needed because it would all be preconfigured. Webmin seems great, but way too complex for them to use.
Any ideas? Can I simplify webmin to do these things and sort of hide it from their view?
-Thanks
You didn't read the link I gave you in my first reply. PhP's exec function will let you run whatever scripts you want. Check into it and be sure to read the warnings: http://us2.php.net/function.exec
It's easy. Make a page with the exec function. Make another page with the button to press. Have the link in the button go to the page. I thought the php manual covered this topic pretty thoroughly but if you have any more questions there are plenty of people on this forum who can help out. Some of them will even write it for you. Alas, I must go work to feed the family.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.