Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Shell Script is not executing with php script

Links for php scripts

Moderators: macek, egami, gesf

Shell Script is not executing with php script

Postby Dheeraj » Mon Jun 04, 2012 9:33 pm

I added following line to run shell script in my php file

$output = shell_exec('./script.sh');
echo $output;

and my script.sh looks like
#!/bin/sh
echo etherX|sudo -S chmod 777 upload/*

cd /home/mnit/Desktop/cuckoo_0.3.2

echo "Inside -- "
pwd

when i execute script.sh by terminal it works but not working by php-script in browser.
Dheeraj
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Jun 04, 2012 9:22 pm

Re: Shell Script is not executing with php script

Postby Emy » Mon Jun 04, 2012 9:57 pm

I think it is a disabled function on the server side, if you have access to the server php.ini, then you could delete it, otherwise contact your server admin, reason it is disabled, is for security reason:

Code: Select all
disable_functions = symlink,shell_exec,exec,proc_close,proc_open,popen,system,dl,passthru,escapeshellarg,escapeshellcmd
Emy
New php-forum User
New php-forum User
 
Posts: 16
Joined: Sat Jun 02, 2012 8:16 pm

Re: Shell Script is not executing with php script

Postby ejsexton82 » Tue Jun 05, 2012 11:04 am

You also have to be careful when specifying relative paths using dot notation. I had a lot of trouble myself getting shell scripts to execute in both the PHP client and on the website.

I always specify a path relative to the PHP file now:

Code: Select all
$output = shell_exec(dirname(__FILE__) . '/script.sh');
User avatar
ejsexton82
New php-forum User
New php-forum User
 
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey


Return to PHP Scripts

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

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