PHP执行shell_exec命令但不执行任何操作

时间:2016-09-24 15:42:32

标签: php mysql bash shell curl

我使用此脚本在post.sh文件中使用curl发布一些日期

#!/bin/sh

var1=`base64 javascript_100.file`

# post it 3 times
for i in `seq 1 3`; do

/usr/bin/curl -i --verbose -d "jobTexterea=$var1" http://my_server_address/target_page.php

done

使用我的Shell执行post.sh文件时没有任何问题,但是当我使用shell_exec('sh /path_to_post_file/post.sh')在我的php脚本中调用它时,我从var_dump(shell_exec('sh /path_to_post_file/post.sh'));收到此错误}。

  

错误:()HTTP / 1.1 302发现日期:2016年9月24日星期六15:14:38 GMT服务器:Apache / 2.4.23(Fedora)OpenSSL / 1.0.2h-fips PHP / 5.6.25 mod_perl / 2.0 .9 Perl / v5.22.2 X-Powered-By:PHP / 5.6.25位置:http://my_server_ ddress / Content-Length:401 Content-Type:text / html; charset = UTF-8发生了MySQL错误。   您的查询:INSERT INTO jobsNum_pro_batch(job_batch_idjobs_in_batchjob_type)VALUES(' 26',' 1',' JavaScript& #39;)

post.sh 文件中的代码将信息发布到 target_page.php ,将所有内容放入数据库中的不同表中。问题是,从PHP页面运行shell_exec('sh /path_to_post_file/post.sh')时,没有信息被上传到数据库中。但是,命令本身运行没有错误,我用

检查
<?php
    if (shell_exec('sh /path_to_post_file/post.sh')){ 
        echo "<b> shell_exec was executed </b><br>";
        var_dump(shell_exec('sh /path_to_post_file/post.sh'));
    } else {
        echo "<b> shell_exec was not executed </b><br>";
    }
?>

我收到消息 shell_exec已执行

有谁知道出了什么问题?

1 个答案:

答案 0 :(得分:0)

这就是诀窍!感谢@ Jean-FrançoisFabre,对他的代码进行了一些小改动,问题就消失了!

#!/bin/sh

progdir=$(dirname $0)

var1=`base64 $progdir/javascript_100.file`

# post it 3 times
for i in `seq 1 3`; do

/usr/bin/curl -i --verbose -d "jobTexterea=$var1" http://my_server_address/target_page.php

done 
相关问题