varnishlog: multiple TxStatus codes - varnish

If there a way to log multiple TxStatus codes with varnishlog ?
Varnishlog man states that there not :)
How could I log multiple codes ?
My command now looks like varnishlog -c -m TxStatus:301
Thank you in advance!

You can try this syntax:
{ varnishlog -c -m TxStatus:301 & varnishlog -c -m TxStatus:404 & } > varnish-status.log
To view live logs:
tail -f varnish-status.log
To stop logging:
$ ps ax | grep varnishlog
5009 pts/0 S 0:00 varnishlog -c -m TxStatus:301
5010 pts/0 S 0:00 varnishlog -c -m TxStatus:404
5636 pts/0 S+ 0:00 grep varnishlog
$ kill 5009
$ kill 5010

Related

How to create alias command to stop celery

Following this solution from another post I've made an alias in my .zshrc (I use ohmyzsh) to stop my celery workers:
alias stopcelery="ps auxww | grep 'celery' | awk '{print $2}' | xargs kill -9"
However when I have running celery workers, using this command fails:
➜ stopcelery
kill: invalid argument
Usage:
kill [options] <pid> [...]
Options:
<pid> [...] send signal to every <pid> listed
-<signal>, -s, --signal <signal>
specify the <signal> to be sent
-l, --list=[<signal>] list all signal names, or convert one to a name
-L, --table list all signal names in a nice table
-h, --help display this help and exit
-V, --version output version information and exit
For more details see kill(1).
The workers are still running:
➜ ps auxww | grep 'celery'
myuser 49126 67.0 0.5 189132 92280 ? S 15:59 0:02 /home/myuser/.local/share/virtualenvs/myproject-JLNbaOhA/bin/python -m celery worker -A wsgi.celery --loglevel=INFO --logfile=/tmp/celery.log --pidfile=celeryd.pid
myuser 49304 0.0 0.5 188160 85060 ? S 15:59 0:00 /home/myuser/.local/share/virtualenvs/myproject-JLNbaOhA/bin/python -m celery worker -A wsgi.celery --loglevel=INFO --logfile=/tmp/celery.log --pidfile=celeryd.pid
myuser 49305 0.0 0.5 188164 84844 ? S 15:59 0:00 /home/myuser/.local/share/virtualenvs/myproject-JLNbaOhA/bin/python -m celery worker -A wsgi.celery --loglevel=INFO --logfile=/tmp/celery.log --pidfile=celeryd.pid
myuser 49306 0.0 0.5 188168 84848 ? S 15:59 0:00 /home/myuser/.local/share/virtualenvs/myproject-JLNbaOhA/bin/python -m celery worker -A wsgi.celery --loglevel=INFO --logfile=/tmp/celery.log --pidfile=celeryd.pid
myuser 49307 0.0 0.5 188172 84844 ? S 15:59 0:00 /home/myuser/.local/share/virtualenvs/myproject-JLNbaOhA/bin/python -m celery worker -A wsgi.celery --loglevel=INFO --logfile=/tmp/celery.log --pidfile=celeryd.pid
myuser 49312 0.0 0.0 20556 2924 pts/8 S+ 15:59 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox celery
But using the actual command it works:
➜ ps auxww | grep 'celery' | awk '{print $2}' | xargs kill -9
kill: (48078): No such process
Indeed, checking again:
➜ ps auxww | grep 'celery'
myuser 49782 0.0 0.0 20556 664 pts/8 S+ 16:03 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox celery
So what is the difference, why using the alias does not having the same effect?
As #Philippe has pointed out, I forgot to escape the $ sign as I was using double quotes.

how can I find who call my bash application

This may look a silly simple question, but I can't find the appropriate method to find the caller.
I have a tool that can be used from different applications. I want to record who is using it.
Note that when sourcing, using source (or the dot shortcut), the executing program is bash (or your designated shell). In this case, only if you source 'tool', the calling history will be preserved on ${BASH_SOURCE[*]}, including the calling line on ${BASH_LINENO[*]}.
I expect BASH_SOURCE give some hint (history), however, the tool is not sourced so, there is no references to caller on 'BASH_SOURCE'.
#!/bin/bash
# this is the tool: I'm expecting to have 'client' somewhere
echo "Source ${BASH_SOURCE[*]}"
ps -axj | grep "\s$$\s"
echo "tool: ${*}"
now, this is the client caller
#!/bin/bash
# this is the client
chmod +x ./tool # I'm making this explicit
./tool this is a test
This is the result:
$ . ./client
Source ./tool
30389 17217 17217 30389 pts/1 17217 S+ 0 0:00 /bin/bash ./tool this is a test
17217 17218 17217 30389 pts/1 17217 R+ 0 0:00 ps -axj
17217 17219 17217 30389 pts/1 17217 S+ 0 0:00 grep \s17217\s
30380 30389 30389 30389 pts/1 17217 Ss 0 0:01 -bash
tool: this is a test
This might help with Linux:
#!/bin/bash
GPPID=$(ps -o ppid= -p $PPID | tr -d ' ')
cat /proc/$GPPID/comm
Would adding ps -o comm= -p $PPID to tool do what you're after?
Edit:
Adding sample output
tink#box ~/tmp$ ./client
Source ./tool
15576 15578 15576 9978 pts/3 15576 S+ 1000 0:00 /bin/bash ./tool this is a test
tool: this is a test
client

Why doesn't "xargs sudo perf top" work as expected?

I want to profile a process, so first get its pid, then use "perf top" to check it:
$ pgrep program
14472
$ sudo perf top -p 14472
It works as expected:
Then I want to use pipe to connect these two commands, so I use xargs:
$ pgrep program | sudo xargs perf top -p
But this time "perf top" seems not work normally:
I compared processes of these two operations:
(1) Run pgrep and perf separately:
$ ps -ef | grep perf
root 18468 16827 0 09:34 pts/3 00:00:00 sudo perf top -p 14472
root 18469 18468 91 09:34 pts/3 00:00:06 perf top -p 14472
nanxiao 18477 18295 0 09:34 pts/4 00:00:00 grep --color=auto perf
(2) Use xargs to connect pgrep and perf:
$ ps -ef | grep perf
nanxiao 18250 16827 0 09:32 pts/3 00:00:00 xargs sudo perf top -p
root 18251 18250 0 09:32 pts/3 00:00:00 sudo perf top -p 14472
root 18252 18251 87 09:32 pts/3 00:01:47 perf top -p 14472
nanxiao 18442 18295 0 09:34 pts/4 00:00:00 grep --color=auto perf
IMHO, it seems same. Anyone can give some clues? Thanks in advance!
P.S., my OS is CentOS 7.
After checking manual again, I find -o option can fix this issue:
-o, --open-tty
Reopen stdin as /dev/tty in the child process before executing
the command. This is useful if you want xargs to run an
interactive application.
The command is like this:
$ pgrep program | sudo xargs -o perf top -p
But unfortunately, CentOS 7's xargs is a little old, and doesn't provide this option.
The root cause is: without -o option, the stdin of perf program is /dev/null:
$ sudo lsof -p 1495
......
perf 1495 root 0r CHR 1,3 0t0 2052 /dev/null
......
And the perf is blocked in SLang_getkey():
......
FD_ZERO(&read_set);
FD_SET(0, &read_set);
if (delay_secs) {
timeout.tv_sec = delay_secs;
timeout.tv_usec = 0;
}
err = select(1, &read_set, NULL, NULL, ptimeout);
if (err == 0)
return K_TIMER;
if (err == -1) {
if (errno == EINTR)
return K_RESIZE;
return K_ERROR;
}
key = SLang_getkey();
if (key != K_ESC)
return key;
......
Read of /dev/null will return EOF, then select() will return 1.
With -o option the stdin of perf program is /dev/tty:
$ sudo lsof -p 1394
......
perf 1394 root 0u CHR 136,25 0t0 28 /dev/pts/25
......
In above code, the select() will return 0, and the whole function will return accordingly.
A better approach would be to directly run the top on the output of pgrep instead of piping over xargs. I believe top command by default does not read information over standard input
sudo perf top -p "$(pgrep program)"
This way the $(..) returns the output of the pgrep command and the returned value is passed as a positional argument value to the -p flag.

issue with restarting autossh reverse tunnel on boot

I seem to have a weird issue:
I want to restart a reverse ssh tunnel on boot, I've tried it with an init script (that works fine when executed as user) and with an added line in /etc/rc.d but none of it works. What I get after boot is:
$ ps ax | grep autossh
397 pts/10 S+ 0:00 grep --color=auto autossh
1351 ? Ss 0:00 /usr/lib/autossh/autossh -M 22221 -N -o PubkeyAuthentication=yes -o PasswordAuthentication=no -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu#server
but I'm unable to login from server. So I did the following after boot:
$ sudo killall -KILL autossh
[sudo] password for ron:
$ /usr/bin/autossh -M 22221 -f -N -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu#server
upon which I can login using port 19999 just fine!
The keys permissions look like: (but root should not need to care, would it?)
$ ls -l ~/.ssh/etherwan.key
-r-------- 1 ron ron 1675 Nov 6 04:15 /home/ron/.ssh/etherwan.key
Replace ~/.ssh/etherwan.key in your rc.d script with /home/ron/.ssh/etherwan.key
The '~' character is expanded to the user's home directory by the shell, but rc.d scripts are run as root.

How to stop password visibile on ps while using curl

I am currently using,
curl -u ${username}:${password} --output /dev/null ${url}
I believe by this approach password will be visible in ps tree. Is there any approach I can use by avoiding this?
The contents of -u are not visible via ps, but remember your History file.
Generally you should avoid Passwords in parameters!
If you downvote.. better tell why:
running a curl -u user:password nopaste.info/login
`--> ps aux | grep curl
t4c 30540 0.0 0.0 103516 2668 pts/5 S+ 13:12 0:00 curl -u nopaste.info/login
As you can see there is no -u output attached.

Resources