php – SSH似乎不能在通过Web服务器调用的bash脚本中运行
我有一个简单的
shell脚本:
>在远程计算机上创建目录. 两台服务器都通过公钥配置SSH无密码登录. 在命令行运行脚本运行良好.从PHP shell_exec命令从服务器运行它将执行脚本,但ssh和scp命令似乎没有执行,或者至少不输出任何内容,即使我使用-v标志. 这是调用shell脚本的PHP函数: function mobi_watermark($userid,$email,$epubpath) { $outpath = "/tmp/epub$userid/"; # the book gets marked for each user,store each epub under a unique work folder to avoid collision shell_exec("chmod -R 777 ".$outpath); # web server creates files under user "nobody". shell_exec("del.sh"); # deletes old files if they exist shell_exec("rep.sh $userid $email $epubpath"); # creates the initial .epub and tmp dir shell_exec("chmod -R 777 ".$outpath); shell_exec("kindle.sh $outpath"); # this is the mobi conversion,where the problem is $this->mobi_ufa_download('ufa-187.mobi',$outpath); } 这是带有失败命令的shell脚本: #!/usr/local/bin/bash # uses the same /tmp$userid path as the other scripts,but on the remote server TMPPATH=$1 cd $TMPPATH # create remote dir ssh -v user@server 'mkdir -v '$TMPPATH # copy the source epub file to remote scp -v $TMPPATHfile-name.epub user@server:$TMPPATH # perform the conversion and copy the .mobi result back to originating server /usr/bin/ssh -v user@server 'cd '$TMPPATH'; /home/username/kindlegen/kindlegen ./file-name.epub; scp -v file-name.mobi user@originating-server:'$TMPPATH';rm -rf '$TMPPATH 如果我从脚本文件中运行这一系列命令,或者自己从命令行运行单独的命令,那么这一切都可以完美地运行. 当通过php脚本运行时,如果我决定回显测试命令,我可以看到脚本输出,如果我中断源文件名,scp将报告错误,但是如果scp或ssh命令正确则没有任何反应. -v标志甚至没有任何详细的调试输出. 我一定错过了一些明显的东西?我猜这是因为PHP正在使用SSH不喜欢的用户’nobody’.如果这是问题,有没有办法解决这个问题?
您可能想尝试添加
</dev/null 在违规命令的最后,只是在某种程度上命令需要输入的情况下. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |