Search a string after match [closed] - perl

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I have a file which has multiple record of netstat output, my sample file looks something like the one below. I want to search for PID for ex : 3453, part of the output I also want to see snapshot time, so that I can find whether PID was exist part of particular snapshot or not. Any thoughts?
zzz ***Sat Apr 11 03:00:26 UTC 2020
USER PID PPID PRI %CPU %MEM VSZ RSS WCHAN S STARTED TIME COMMAND
test 1234 3445 19 2.4 1.9 4070932 3539756 futex_wait_queue_ S Apr 04 04:00:17 test -quiet
test1 3453 6741 19 2.4 1.9 4070932 3539756 futex_wait_queue_ S Apr 04 04:00:17 test -quiet
zzz ***Sat Apr 11 03:01:26 UTC 2020
USER PID PPID PRI %CPU %MEM VSZ RSS WCHAN S STARTED TIME COMMAND
test 3453 3453 19 2.4 1.9 4070932 3539756 futex_wait_queue_ S Apr 04 04:00:17 test -quiet
test1 7842 8712 19 2.4 1.9 4070932 3539756 futex_wait_queue_ S Apr 04 04:00:17 test -quiet
Expected sample output for search 3453:
zzz ***Sat Apr 11 03:00:26 UTC 2020
test1 3453 6741 19 2.4 1.9 4070932 3539756 futex_wait_queue_ S Apr 04 04:00:17 test -quiet
zz ***Sat Apr 11 03:01:26 UTC 2020
test 3453 3453 19 2.4 1.9 4070932 3539756 futex_wait_queue_ S Apr 04 04:00:17 test -quiet

With GNU sed:
sed -n '/\*\*\*/,/^$/{ /\*\*\*/p; /3453/p }' file
Output:
zzz ***Sat Apr 11 03:00:26 UTC 2020
test1 3453 6741 19 2.4 1.9 4070932 3539756 futex_wait_queue_ S Apr 04 04:00:17 test -quiet
zzz ***Sat Apr 11 03:01:26 UTC 2020
test 3453 3453 19 2.4 1.9 4070932 3539756 futex_wait_queue_ S Apr 04 04:00:17 test -quiet
See: man sed and The Stack Overflow Regular Expressions FAQ

Related

why terminal output can't be saved to file when there's core dumped

I'm running an executable and trying to save terminal output to a file:
# ll
total 132
-rw-r--r--. 1 root root 496 Jun 14 11:41 mpx-debug.h
-rw-r--r--. 1 root root 12775 Jun 14 11:41 mpx-dig.c
-rw-r--r--. 1 root root 3526 Jun 14 11:41 mpx-hw.h
-rwxr-xr-x. 1 root root 65176 Jun 14 14:28 mpx-mini-test
-rw-r--r--. 1 root root 40480 Jun 14 11:41 mpx-mini-test.c
-rw-r--r--. 1 root root 205 Jun 14 11:41 mpx-mm.h
# ./mpx-mini-test
XSAVE is supported by HW & OS
XSAVE processor supported state mask: 0x1f
XSAVE OS supported state mask: 0x1f
BNDREGS: size: 64 user: 1 supervisor: 0 aligned: 0
BNDCSR: size: 64 user: 1 supervisor: 0 aligned: 0
no MPX support
Aborted (core dumped)
#
# ./mpx-mini-test | tee -a mpx-mini-test.log
#
# cat mpx-mini-test.log
#
As you can see, there're some prints in terminal without "| tee -a **.log".
But with "| tee -a **.log", nothing is saved to file.
I suspect it has something to do with the "Abort (core dumped)", did some googling but can't figure out exactly why. Is there anyone knows why? And how could I save all terminal outputs(including the "Abort (core dumped)") to file? Thanks in advance.

Has anyone tried using the bitbake-env utility lately?

Has anyone tried using the bitbake-env utility lately?
I do not see it installed:
[user#localhost build]$ which bitbake
~/YOCTO/oe_core_embedded/poky/bitbake/bin/bitbake
[user#localhost build]$ which bitbake-env
/usr/bin/which: no bitbake-env in (/home/user/YOCTO/oe_core_embedded/poky/scripts:/home/user/YOCTO/oe_core_embedded/poky/bitbake/bin:/usr/libexec/python2-sphinx:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/user/.local/bin:/home/user/bin)
[user#localhost build]$
As well I do not see it in the bitbake command listing:
[user#localhost poky]$ cd bitbake/bin
[user#localhost bin]$ ls -al
total 100
drwxrwxr-x. 2 user user 4096 Oct 18 12:49 .
drwxrwxr-x. 6 user user 4096 Oct 18 12:49 ..
-rwxrwxr-x. 1 user user 2072 Nov 18 11:51 bitbake
-rwxrwxr-x. 1 user user 7228 Oct 18 12:49 bitbake-diffsigs
-rwxrwxr-x. 1 user user 2894 Oct 18 12:49 bitbake-dumpsig
-rwxrwxr-x. 1 user user 4069 Oct 18 12:49 bitbake-layers
-rwxrwxr-x. 1 user user 2109 Oct 18 12:49 bitbake-prserv
-rwxrwxr-x. 1 user user 2128 Oct 18 12:49 bitbake-selftest
-rwxrwxr-x. 1 user user 17866 Oct 18 12:49 bitbake-worker
-rwxrwxr-x. 1 user user 13951 Oct 18 12:49 bitdoc
-rwxrwxr-x. 1 user user 5813 Oct 18 12:49 git-make-shallow
-rwxrwxr-x. 1 user user 8805 Oct 18 12:49 toaster
-rwxrwxr-x. 1 user user 4177 Oct 18 12:49 toaster-eventreplay
[user#localhost bin]$
It still exists/is listed in https://elinux.org/Bitbake_Cheat_Sheet from July 2016.
bitbake-env is a third party utility, and not actually a part of the OpenEmbedded Core hence why you will not see it unless you specifically install it. It is actually an 'improved' version of the bitbake -e flag for bitbake.
bash-4.3$ bitbake --help
Usage: bitbake [options] [recipename/target recipe:do_task ...]
Executes the specified task (default is 'build') for a given set of target recipes (.bb files).
It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which
will provide the layer, BBFILES and other configuration information.
Options:
...
-e, --environment Show the global or per-recipe environment complete
with information about where variables were
set/changed.

Manually install Emacs feature

I have a question about Emacs customisation.
For example, there is a git repo like https://github.com/bbatsov/projectile.
The directory structure is like:
-rw-r--r-- 1 haoruan staff 12K Nov 7 16:30 CHANGELOG.md
-rw-r--r-- 1 haoruan staff 1.5K Nov 7 16:30 CONTRIBUTING.md
-rw-r--r-- 1 haoruan staff 138B Nov 7 16:30 Cask
-rw-r--r-- 1 haoruan staff 884B Nov 7 16:30 Makefile
-rw-r--r-- 1 haoruan staff 28K Nov 7 16:30 README.md
-rw-r--r-- 1 haoruan staff 39K Nov 7 16:30 helm-projectile.el
-rw-r--r-- 1 haoruan staff 4.4K Nov 7 16:30 persp-projectile.el
-rw-r--r-- 1 haoruan staff 112K Nov 7 16:30 projectile.el
drwxr-xr-x 7 haoruan staff 238B Nov 7 16:30 screenshots
drwxr-xr-x 3 haoruan staff 102B Nov 7 16:30 script
drwxr-xr-x 7 haoruan staff 238B Nov 7 16:30 test
drwxr-xr-x 3 haoruan staff 102B Nov 7 16:30 travis
It is suggested that the recommended way to install this feature is using MELPA. I can clone this git repo, but I can not ping MELPA. My question is how can I manually install this Emacs feature? More generic, how can I manually install such a Emacs feature which is using cask?
In your example,you dose not need cask
git clone https://github.com/bbatsov/projectile /some/place/you/want
Then add
(add-to-load-path "/some/place/you/want")
in your .emacs or init.el.Then
(require 'projectile)
manually.

Outgoing mails limit in Qmail

I was googling and found this link helpful https://serverfault.com/questions/538233/qmail-limit-number-of-emails-sent-by-user-or-domain-per-hour
My OS is Centos with Plesk 11.x + Qmail
I tried my best to follow given directives in the link e.g.
1) I installed spamdkye successfully
2) Created mkdir -p /home/vpopmail/bin/qmail-antispam
3) mkdir -p /etc/qmailadmin/qmail-spam/blacklist
4) crontab -e
*/5 * * * * /home/vpopmail/bin/qmail-antispam >> /var/log/maillog 2>&1
5) I saved script as qmail-antispam as well as moved as blacklist but on both positions it displays:
Code:
# tail -f /var/log/maillog | grep "qmail-antispam"
/bin/sh: /home/vpopmail/bin/qmail-antispam: is a directory
/bin/sh: /home/vpopmail/bin/qmail-antispam: is a directory
Tue Oct 20 12:55:01 CDT 2015 qmail-antispam : Revisando logs
Tue Oct 20 12:55:01 CDT 2015 qmail-antispam : Fin de revision
Tue Oct 20 13:00:01 CDT 2015 qmail-antispam : Revisando logs
Tue Oct 20 13:00:01 CDT 2015 qmail-antispam : Fin de revision
Questions:
Please advise where:
1) where I save this script either in /etc/qmailadmin/qmail-spam/blacklist or /home/vpopmail/bin/qmail-antispam and with which name?
2) MAX_CORREOS=3000 //is that to set maximum limit??
ID_SERVER="ID_SERVER" //May I change this to my server hostname??
CONTACTO=admin#gmail.com //Here I set admin email to send report. Is that right??
Please advise
Thanks in anticipation
vi /home/vpopmail/bin/qmail-antispam
copy & paste the script provided in Link
Edit script and change following:
MAX_CORREOS=100
ID_SERVER="my server hostname"
CONTACTO=admin#gmail.com
# chown root /home/vpopmail/bin/qmail-antispam
# chmod 755 /home/vpopmail/bin/qmail-antispam
and check its working fine:
# tail -f /var/log/maillog | grep "qmail-antispam"
Wed Oct 21 19:20:01 CDT 2015 qmail-antispam : Revisando logs
Wed Oct 21 19:25:01 CDT 2015 qmail-antispam : Revisando logs
Wed Oct 21 19:30:01 CDT 2015 qmail-antispam : Revisando logs
Wed Oct 21 19:35:01 CDT 2015 qmail-antispam : Revisando logs
Wed Oct 21 19:40:01 CDT 2015 qmail-antispam : Revisando logs
Wed Oct 21 19:45:01 CDT 2015 qmail-antispam : Revisando logs
Wed Oct 21 19:50:01 CDT 2015 qmail-antispam : Revisando logs
Wed Oct 21 19:55:01 CDT 2015 qmail-antispam : Revisando logs
Wed Oct 21 20:00:01 CDT 2015 qmail-antispam : Revisando logs

How is the /proc/pid/fd/0, 1, 2 is linked to tty device?

Linux process link stdin/output/err to /dev/tty, for example:
ls -all /proc/5310/fd show
lrwx------ 1 ubuntu ubuntu 64 Mar 31 09:58 0 -> /dev/pts/1
lrwx------ 1 ubuntu ubuntu 64 Mar 31 09:58 1 -> /dev/pts/1
lrwx------ 1 ubuntu ubuntu 64 Mar 31 09:58 2 -> /dev/pts/1
Which component in system is in charge of the link? How it link the fd 0/1/2 to /dev/pts/1? How can I change it to be /dev/pts/2