对于想了解phpshellexecwget不在后台运行的读者,本文将提供新的信息,我们将详细介绍phpshell_exec,并且为您提供关于bash–shell_exec无法在phpwebappl中运
对于想了解php shell exec wget不在后台运行的读者,本文将提供新的信息,我们将详细介绍php shell_exec,并且为您提供关于bash – shell_exec无法在php web appl中运行、linux exec 和 shell_exec函数_PHP教程、Linux Shell,在后台运行命令时显示内容、linux – 无法通过php exec运行shell命令,但可以作为shell上的用户吗?的有价值信息。
本文目录一览:- php shell exec wget不在后台运行(php shell_exec)
- bash – shell_exec无法在php web appl中运行
- linux exec 和 shell_exec函数_PHP教程
- Linux Shell,在后台运行命令时显示内容
- linux – 无法通过php exec运行shell命令,但可以作为shell上的用户吗?
php shell exec wget不在后台运行(php shell_exec)
shell_exec('wget "'http://somedomain.com/somefile.mp4'"'); sleep(20); continue my code...
我想要的是让PHP等待shell_exec wget文件下载完成后再继续使用其余的代码.我不想等待一定的秒数.
我该怎么做,因为当我运行shell_exec wget时,该文件将开始下载并在后台运行,PHP将继续.
解决方法
例如,如果$url是“http://www.example.com/?foo=1\u0026amp;bar=2”,则需要确保在命令行传递时它是单引号:
shell_exec("wget '$url'");
否则shell会误解& ;.
一般来说,转义命令行参数是一个好主意.最全面的方法是使用escapeshellarg():
shell_exec("wget ".escapeshellarg($url));
bash – shell_exec无法在php web appl中运行
该脚本具有执行权限.通常,脚本会将网络接口列表(eth0 eth1 wlan0)保存在名为“resultat”的文件中,但是当我使用PHP的shell_exec命令从网页运行此脚本时(echo-password for www-data user’| / usr) / lib / cgi-bin / sudo -S global.sh bin / bash /“)没有生成输出.
如果我在终端中运行与用户www-data相同的脚本,则会正确填充结果文件.
剧本:
#!/bin/bash ##### paramères relatives au connexion à la base de données HOST_BDD="localhost" LOGIN="root" PASSWD="password" NOM_BDD="dbnessus" ##### ces requettes pour vider les tables avant de faire la detection vider2="TruncATE machine_connecte" echo $vider2 | /usr/bin/MysqL -h $HOST_BDD -u $LOGIN -p$PASSWD -s $NOM_BDD vider1="TruncATE interfaces" echo $vider1 | /usr/bin/MysqL -h $HOST_BDD -u $LOGIN -p$PASSWD -s $NOM_BDD initialise="ALTER TABLE machine_connecte AUTO_INCREMENT=0" echo $initialise | /usr/bin/MysqL -h $HOST_BDD -u $LOGIN -p$PASSWD -s $NOM_BDD ####################################################### /usr/lib/cgi-bin/get_interface.sh > /usr/lib/cgi-bin/liste_interfaces while read line; do ip=$(/usr/lib/cgi-bin/get_ip.sh $line) mask=$(/usr/lib/cgi-bin/get_netmask.sh $line) bcast=$(/usr/lib/cgi-bin/get_bcast.sh $line) ###fonction is_alive_ping is_alive_ping() { ping -i 100 -c 1 $1 > /dev/null 2> /dev/null [ $? -eq 0 ] && echo $i >>/usr/lib/cgi-bin/resultat } cat /dev/null >/usr/lib/cgi-bin/resultat; ######### ###division des octet d'adresse de broadcst if [ "$ip" != "" ] then i1="$(echo $bcast |cut -d"." -f1)" i2="$(echo $bcast |cut -d"." -f2)" i3="$(echo $bcast |cut -d"." -f3)" i4="$(echo $bcast |cut -d"." -f4)" fi ### { HostID / NetworkID } / classe du réseau ##################### A.255.255.255 Classe A if [ "$i2" == "255" ] then for i in "$i1".{1..254}.{1..254}.{1..254} do is_alive_ping $i & disown done fi ##################### A.B.255.255 Classe B if [ "$i2" != "255" ] && [ "$i3" == "255" ] then for i in "$i1.$i2".{1..254}.{1..254} do is_alive_ping $i & disown done fi ##################### A.B.C.255 Classe C if [ "$i2" != "255" ] && [ "$i3" != "255" ]&& [ "$i4" == "255" ] then for i in "$i1.$i2.$i3".{1..254} do is_alive_ping $i & disown done fi ################ while read ip_up; do hostname=$(/usr/bin/resolveip -s $ip_up 2>/dev/null) if [ "$hostname" == "" ] then hostname="*" fi mac=$(/usr/sbin/arp -a $ip_up |cut -d" " -f4) if [ "$ip_up" == "$ip" ] then mac=$(/sbin/ifconfig $line |grep 'HWaddr'|grep -v '127.0.0.1'|awk '{ print $5}') fi OS=$( /usr/bin/nmap -A $ip_up |grep "Service Info:" |awk '{print $4,$5}' ) if [ "$OS" == "Unix,Linux" ] || [ "$OS" == "Linux" ] then OS="Linux" elif [ "$OS" == "Windows " ] then OS="Windows" else OS="*" fi #sql1="INSERT INTO dbnessus.interfaces (nom_interface)VALUES ('$line');" sql1="INSERT IGnorE INTO dbnessus.interfaces (nom_interface)VALUES ('$line');" sql2="INSERT INTO dbnessus.machine_connecte (idmachine,ip_mach,mask_mach,nom_mach,mac_mach,os_mach,interfaces_nom_interface)VALUES ( NULL,'$ip_up','$mask','$hostname','$mac','$OS','$line');" echo $sql1 | /usr/bin/MysqL -h $HOST_BDD -u $LOGIN -p$PASSWD -s $NOM_BDD echo $sql2 | /usr/bin/MysqL -h $HOST_BDD -u $LOGIN -p$PASSWD -s $NOM_BDD done < /usr/lib/cgi-bin/resultat ip="" done < /usr/lib/cgi-bin/liste_interfaces echo "cbon"
解决方法
>检查shell_exec是否在PHP.ini的disabled_functions中
(PHP.ini:disabled_functions)
>确保PHP未以安全模式运行
(PHP.ini:safe_mode)
>确保PHP-fpm进程(如果使用PHP-fpm)或https(如果使用apxs)在足够的权限下工作(运行shell脚本并在脚本中执行这些命令)
(在这种情况下,你可以su到该用户,看看你是否可以从bash运行它)
对不起,到目前为止我无法想到更多……
linux exec 和 shell_exec函数_PHP教程
popen,passthru,proc_open,shell_exec的返回结果如下:
[root@krlcgcms01 shell]# php test.php 1001.log 10.log 10.tar.gz aaa.tar.gz mytest test1101 test1102 weblog_2010_09 我能发现的就这几个函数,能执行
一般情况下,很少会用php去执行linux命令,不过特殊情况下,你也许会用到这些函数。以前我知道有二个函数可以执行linux命令,一个是exec,一个是shell_exec。其实有很多的,结合手册内容,介绍以下6个函数。
立即学习“PHP免费学习笔记(深入)”;
1,exec函数
返回结果如下:
[root@krlcgcms01 shell]# php ./exec.php array ( [0] => 1001.log [1] => 10.log [2] => 10.tar.gz [3] => aaa.tar.gz [4] => mytest [5] => test1101 [6] => test1102 [7] => weblog_2010_09 )
Linux Shell,在后台运行命令时显示内容
sudo apt-get install eclipse --yes
而不是在安装它时显示命令的详细信息,显示一个加载条,如
……
(点加载时会弹出点或其他东西)
我试过做类似的事情
apt=sudo apt-get install vlc --yes start() { $apt while $apt; do echo -n "." sleep 0.5 done } start
(我打算做的是运行$apt变量,然后让它继续运行到while循环,while循环将确定命令是否正在运行,所以当命令运行时,它将用点替换verbose)
解决方法
spinner() { local pid=$! local delay=0.75 local spinstr='...' echo "Loading " while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do local temp=${spinstr#?} printf "%s " "$spinstr" local spinstr=$temp${spinstr%"$temp"} sleep $delay printf "\b\b\b" done printf " \b\b\b\b" }
用法:
(a_long_running_task) & spinner
打印出来
Loading …
Loading ….
Loading …..
Loading ……
当然在同一条线上.
linux – 无法通过php exec运行shell命令,但可以作为shell上的用户吗?
奇怪的是,在我的本地主机上一切都很好,但在我的服务器上却没有.
如上所述,通过ssh登录的exiftool命令运行正常.
但是在PHP测试脚本中运行(注意我已经在每个测试目录上安装了exiftool,并且它通过ssh运行),没有任何东西可以访问,尽管它以用户orangeman运行…
它失败了
这是一个更新 – 整天都在这里:
在shell上:
-bash-4.1$which exiftool -a ~/perl5/bin/exiftool /usr/bin/exiftool ~/perl5/bin/exiftool
在PHP shell_exec(‘exiftool -a’);
/usr/bin/exiftool
以下是该文件链接到的内容:
lrwxrwxrwx 1 root root 33 May 15 02:10 exiftool -> /home/orangeman/perl5/bin/exiftool
我也尝试创建各种符号链接,通过putenv()篡改主$PATH变量;在PHP …我真的在这里黑暗.适用于localhost,而不是专用服务器.
我用赏金更新了这个 – 这是一个严重的问题.
我在专用服务器上,问题如上所述.
UPDATE
根据@gcb的建议,我能够打印出PHP的exec()函数运行系统命令时发生的错误.
PHP
<?PHP exec('exiftool 2>&1',$output,$r); var_dump($output,$r); ?>
输出:
array(2) { [0]=> string(230) "Can't locate Image/ExifTool.pm in @INC (@INC contains: /bin/lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /bin/exiftool line 33." [1]=> string(59) "BEGIN Failed--compilation aborted at /bin/exiftool line 33." }
UPDATE
@ gcb的解决方案奏效了.非常感谢你.
解决方法
这里回答http://u88.n24.queensu.ca/exiftool/forum/index.php?topic=2217.0
You either have to install the ExifTool libraries in the standard location (ie. somewhere in the @INC directories listed in your post),or add the location to the include path,something like this: Code: #!/usr/bin/perl BEGIN { unshift @INC,"PATH_TO_DIRECTORY_CONTAINING_LIBRARIES" } use Image::ExifTool; You should be able to add "Image/ExifTool.pm" to the path you add to find the ExifTool module. - Phil
我仍然认为使用上一个答案的#3建议会解决它.如果没有,你真的想知道原因,创建一个新的perl脚本,只输出@INC的内容并通过shell和PHP运行它.你会看到差异,然后你需要找到哪些登录脚本没有在PHP中被尊重并打开一个针对PHP的bug for shell_exec不尊重它…
虽然对您的问题更简单的解决方案(因为它看起来您对解释不太感兴趣)是在调用脚本之前设置PERLLIB var.
那么,就这样做:
> find / -name ExifTool.pm这将告诉你lib的安装位置.让我们说这会返回/example/perl/Image/ExifTool.pm>将PERL5LIB = / example / perl /附加到您的exec()调用.> exec(“PERL5LIB = / example / perl / sudo /var/www/myscript/execscript.sh {$param}”);
今天关于php shell exec wget不在后台运行和php shell_exec的分享就到这里,希望大家有所收获,若想了解更多关于bash – shell_exec无法在php web appl中运行、linux exec 和 shell_exec函数_PHP教程、Linux Shell,在后台运行命令时显示内容、linux – 无法通过php exec运行shell命令,但可以作为shell上的用户吗?等相关知识,可以在本站进行查询。
本文标签: