[英]Running bash script from PHP halts
EDIT 编辑
It seems that I cannot cat /dev/urandom
from a PHP script, please keep this in mind while reading the following 看来我无法从PHP脚本获得
cat /dev/urandom
,请在阅读以下内容时牢记这一点
/EDIT /编辑
I ran into an issue while trying to execute a BASH script from PHP, seems to be halting at generating a rand directory (variable generate
) I can see if I change the variable string to something like foo
as I did in the commented out portion of the script this executes appropriately. 我尝试从PHP执行BASH脚本时遇到问题,似乎在生成rand目录(variable
generate
)时停止了,我可以看到是否将变量字符串更改为foo
东西,就像我在注释部分中所做的那样。适当执行的脚本。
What is the issue with sghell_exec'ing cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
sghell_exec'ing
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
有什么问题? cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
is this a (possibly) restricted command sequence to user(s) www-data (DEB based system) or httpd (RHEL based system) cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
是(可能)限制给用户www-data(基于DEB的系统)或httpd(基于RHEL的系统)的命令序列
The bash script bash脚本
#!/bin/bash
# INP : co.sh ${website} ${branch} ${hash}
set -x # trace
declare -r hostname='localhost'
# bricks
declare -r generate=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# works
#declare -r generate='foo'
declare -r archive="$1" # git repository name
declare -r branchd="$2" # git repo branch name
declare -r hashmap="$3" # git blob hash (6/~)
# if repository or branch is empty...
if [ '' == "${archive}" ] || [ '' == "${branchd}" ]; then
[ '' == "${archive}" ] && echo -e "ERR: Archive must be defined."
[ '' == "${branchd}" ] && echo -e "ERR: Branch must be defined."
exit 1 # err fatal
fi
# clone repository to rand directory
git clone "git@${hostname}:web-archive/${archive}.git" "/var/www/html/${generate}"
cd "/var/www/html/${generate}" && git checkout "${branchd}"
position='HEAD' # pre-warm
[ '' != "${hashmap}" ] &&
{
git reset "${hashmap}" --hard # move to hash blob
position="${hashmap}" # override position
}
# encode for push
json="{'s':'${archive}','b':'${branchd}','h':'${position}','d':'${generate}'}"
echo -e "\nSUCC: ${json}"
The test runner script 测试运行器脚本
#!/usr/bin/php
<?php
$dir=__DIR__; // curr
$site_name='www.foo.com';
$rev_hash='feb2da';
$cmd="$dir/co.sh " . escapeshellarg($site_name) . " 'render' " . escapeshellarg($rev_hash);
echo "running $cmd\n";
$ret = passthru($cmd,$return_status));
trace log 跟踪日志
running /{dir_path}/co.sh 'www.foo.com' 'render' 'feb2da'
+ declare -r hostname=localhost
++ cat /dev/urandom
++ fold -w 32
++ head -n 1
++ tr -dc a-zA-Z0-9
由于PHP不喜欢在/dev/urandom
上运行,因此以下是可以接受的折衷方案
openssl rand -base64 36 | tr -dc 'a-zA-Z0-9'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.