banning in one line command

Miguel González miguel_3_gonzalez at yahoo.es
Thu Feb 2 13:44:18 CET 2017


On 02/02/17 1:05 PM, Dridi Boukelmoune wrote:
>>> you mean varnishadm manual, this one:
>>>
>>> https://varnish-cache.org/docs/4.1/reference/varnishadm.html
>>>
>>> ?
> 
> Yes, I was looking at something else related to varnishstat and endup
> mixing things up. That's the manual I'm referring to.
> 
>>> My experience is that using a singleliner doesn´t work, cache is not
>>> banned. I thought It was the empty string output but considering your
>>> answer and the manual it supposedly works but it´s not actually banning
>>> the cache.
> 
> It works for me:
> 
>     $ cat ban_test.sh
>     #!/bin/sh
> 
>     set -e
> 
>     if varnishadm ban "$1"
>     then
>         echo "Ban added."
>         varnishadm ban.list
>     else
>         echo "Failed to add ban." >&2
>         exit 1
>     fi
> 
>     $ ./ban_test.sh "req.url ~ /foo"
> 
>     Ban added.
>     Present bans:
>     1486036564.163640     0 -  req.url ~ /foo
>     1486036505.008676     0 C
> 
>     $ ./ban_test.sh "req.url =="
>     Unknown request.
>     Type 'help' for more info.
>     Too few parameters
> 
>     Command failed with error code 104
>     Failed to add ban.
> 
>> using quotes an after the example in the manual:
>>
>> echo "ban req.http.host ~ myserver.com" | varnishadm -S /etc/varnish/secret
>> 200
> 
> You shouldn't need to specify -S for a local access with varnishadm.
> 
>> Before I was getting this error when not using commands for the echo
>> command (as showed in the example in the manual):
>>
>> 106
>> expected conditional (~, !~, == or !=) got "/root"
>>
>> apparently this error is dued to the echo command and the use of
>> conditionals as ~
> 
> I suspect you were getting a shell expansion of ~ to the home
> directory of the root user, hence the /root.
> 
> Dridi

Yes, i did :)

Many thanks for your throughly answer!

Miguel



More information about the varnish-misc mailing list