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

execute a linux script from PHP

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

execute a linux script from PHP

Postby Jordi » Mon Jan 13, 2003 2:00 am

Hi all,

I have a simple linux script , with the following code:

/////////////////////////////////////////////

grep ^$1 poppasswd | awk 'BEGIN { FS = "/" } { print $(NF-1) }'

/////////////////////////////////////////////

The script works fine when i execute it from the localhost.

When I execute it from PHP, i dont get any result. i use the following code:

///////////////////////////////////////////////////////////
if (!function_exists('imp_expand_fromaddress')) {
function imp_expand_fromaddress ($imp) {
$cmd = '/usr/local/bin/myscript ' . escapeShellCmd($imp['user']);
$res=exec("$cmd");
return ($res);
}
}

////////////////////////////////////////////////////////////

I think the problem is in the { print $(NF-1) }' in the linux script, because if i add a : echo "name" to the script, the function in PHP works and returns the value "name".

Any idea??

Thanks!
Jordi
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Jan 13, 2003 1:40 am
Location: Barcelona

Re: execute a linux script from PHP

Postby WiZARD » Mon Jan 13, 2003 4:49 am

Try change at this:
Code: Select all
///////////////////////////////////////////////////////////
 if (!function_exists('imp_expand_fromaddress')) {
    function imp_expand_fromaddress ($imp) {
           $cmd = '/usr/local/bin/myscript ' . "'" . escapeShellCmd($imp['user']) . "'";
           $res=exec("$cmd");
           return ($res);
   }
}

or see how to do this smart peaple iwho read manual carefully:
http://www.php.net/manual/en/function.e ... ellarg.php
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Solved

Postby Jordi » Wed Jan 15, 2003 2:42 am

Hi,

the problem was in the linux script, and not in the PHP code.

anyway, thanks for the help.
Jordi
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Jan 13, 2003 1:40 am
Location: Barcelona


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

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

cron