See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Run bash script from php

General Tech Bugs & Fixes

Max. 2000 characters



( 5 months ago )


I want to run a shell script within a php webpage to check some processes running on my system (Ubuntu 12.04). Googleing I've found about shell_exec() but I can't manage to run the script when loading php.

This is the php code I use.

$output = shell_exec('./dirlist.bash');
echo "<pre>$output</pre>";

and the piece of html I get


Also tried $output = shell_exec('sudo -u www-data ./dirlist.bash');

dirlist.bash does ls -l (just for testing script and shell_exec)

I think it is not a permission problem. Running directory grants write and execute privileges for all users (I should be careful here).

drwxrwxrwx  4 meteo meteo 4096 mar 11 15:20 RAMS

User www-data has been added to sudoers file in case it was needed

www-data ALL = (meteo) NOPASSWD: /home/meteo/www/RAMS/dirlist.bash

Thanks in advance

what's your interest