Pass variables from htaccess to bash script
I'm trying to pass the value of a cookie to a bash script:
RewriteCond %{HTTP_COOKIE} mycookie=(.*) [NC]
RewriteRule开发者_运维问答 .* script.sh?cookievar=%1
... but can't seem to find out how to read the GET variable in the bash script. (I suppose I'm asking Google the wrong queries, but can't find any info on this).
Is this even possible, and if so, please how?
Thanks, David
You have to look at QUERY_STRING
environment variable in Bash in order to access GET
variables. In your case it should be set to cookievar=VALUE
. To extract a variable's value, use something like this:
COOKIEVAR=$(echo ${QUERY_STRING} | sed -n -e 's/^.*cookievar=\([^&]*\).*$/\1/p' -e 's/%20/ /g')
Good luck!
精彩评论