0
<kernel>
use_profile 0
use_group 0

file execute /lib64/rc/sh/cgroup-release-agent.sh exec.realpath="/lib64/rc/sh/cgroup-release-agent.sh" exec.argv[0]="/lib64/rc/sh/cgroup-release-agent.sh"
file execute /sbin/init exec.realpath="/sbin/init" exec.argv[0]="/sbin/init"
file execute /sbin/modprobe exec.realpath="/bin/kmod" exec.argv[0]="/sbin/modprobe"

<kernel> /sbin/init
use_profile 0
use_group 0


<kernel> /sbin/init /sbin/openrc
use_profile 0
use_group 0


<kernel> /sbin/init /sbin/openrc /lib64/rc/sh/init-early.sh
use_profile 0
use_group 0

<kernel> /etc/init.d/dmesg
use_profile 0
use_group 0

file execute /lib64/rc/sh/openrc-run.sh exec.realpath="/lib64/rc/sh/openrc-run.sh" exec.argv[0]="/lib64/rc/sh/openrc-run.sh"
file read /etc/rc.conf
file read /run/openrc/depconfig
file read /run/openrc/deptree
file read /sbin/openrc-run
file read proc:/cmdline
file symlink /run/openrc/started/dmesg symlink.target="/etc/init.d/dmesg"
file symlink /run/openrc/starting/dmesg symlink.target="/etc/init.d/dmesg"
file unlink /run/openrc/exclusive/dmesg
file unlink /run/openrc/starting/dmesg
misc env CONFIG_PROTECT
misc env CONFIG_PROTECT_MASK
misc env DCC_EMAILLOG_WHOM_TO_BLAME
misc env DISTCC_ENABLE_DISCREPANCY_EMAIL
misc env DISTCC_FALLBACK
misc env DISTCC_SAVE_TEMPS
misc env DISTCC_SSH
misc env DISTCC_TCP_CORK
misc env DISTCC_VERBOSE
misc env EINFO_LOG
misc env GCC_SPECS
misc env GSETTINGS_BACKEND
misc env GUILE_LOAD_PATH
misc env INFOPATH
misc env LANG
misc env LESS
misc env LESSOPEN
misc env MANPAGER
misc env MANPATH
misc env OPENCL_PROFILE
misc env OPENGL_PROFILE
misc env PATH
misc env QT_GRAPHICSSYSTEM
misc env RC_BOOTLEVEL
misc env RC_DEFAULTLEVEL
misc env RC_LIBEXECDIR
misc env RC_PID
misc env RC_RUNLEVEL
misc env RC_SVCDIR
misc env RC_TMPDIR
misc env RC_UNAME
misc env RC_VERSION
misc env ROOTPATH
misc env TERM
misc env UNCACHED_ERR_FD
misc env VBOX_APP_HOME
misc env XDG_CONFIG_DIRS
misc env XDG_DATA_DIRS
misc env XSESSION


<kernel> /usr/sbin/ntpdate
use_profile 3
use_group 0

misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
misc env TERM
misc env XAUTHORITY
misc env PATH
misc env COLORTERM
misc env MAIL
misc env LOGNAME
misc env USER
misc env USERNAME
misc env HOME
misc env SHELL
misc env SUDO_COMMAND
misc env SUDO_USER
misc env SUDO_UID
misc env SUDO_GID
network unix dgram send /dev/log
file read /etc/nsswitch.conf
file read /etc/services
file read /etc/host.conf
file read /etc/resolv.conf
file read /etc/hosts
network inet dgram send 127.0.0.1 53
file ioctl socket:[family=2:type=2:protocol=17] 0x541B
file read /etc/gai.conf
network inet dgram bind/send :: 123
network inet dgram bind/send 0.0.0.0 123



<kernel> /sbin/init /sbin/openrc /lib64/rc/sh/init-early.sh /usr/bin/loadkeys
use_profile 0
use_group 0


<kernel> /sbin/init /sbin/openrc /lib64/rc/sh/init.sh
use_profile 0
use_group 0


<kernel> /etc/init.d/ntpd
use_profile 3
use_group 0

misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
misc env TERM
misc env XAUTHORITY
misc env PATH
misc env COLORTERM
misc env MAIL
misc env LOGNAME
misc env USER
misc env USERNAME
misc env HOME
misc env SHELL
misc env SUDO_COMMAND
misc env SUDO_USER
misc env SUDO_UID
misc env SUDO_GID
file read /sbin/openrc-run
file read /etc/rc.conf
file read proc:/cmdline
file read /etc/profile.env
file read proc:/cpuinfo
file read proc:/1/environ
file read /run/openrc/softlevel
file create /run/openrc/exclusive/ntpd 0664
file write/unlink /run/openrc/exclusive/ntpd
file symlink /run/openrc/starting/ntpd symlink.target="/etc/init.d/ntpd"
file read /run/openrc/depconfig
file read /run/openrc/deptree
file execute /lib64/rc/sh/openrc-run.sh exec.realpath="/lib64/rc/sh/openrc-run.sh" exec.argv[0]="/lib64/rc/sh/openrc-run.sh"
misc env CONFIG_PROTECT
misc env CONFIG_PROTECT_MASK
misc env GCC_SPECS
misc env GSETTINGS_BACKEND
misc env INFOPATH
misc env LESS
misc env LESSOPEN
misc env MANPAGER
misc env MANPATH
misc env OPENGL_PROFILE
misc env QT_GRAPHICSSYSTEM
misc env ROOTPATH
misc env VBOX_APP_HOME
misc env XDG_CONFIG_DIRS
misc env XDG_DATA_DIRS
misc env RC_VERSION
misc env RC_LIBEXECDIR
misc env RC_SVCDIR
misc env RC_TMPDIR
misc env RC_BOOTLEVEL
misc env RC_RUNLEVEL
misc env RC_DEFAULTLEVEL
misc env RC_UNAME
misc env EINFO_LOG
misc env RC_SVCNAME
misc env RC_OPENRC_PID
misc env RC_RUNSCRIPT_PID
misc env RC_CMD
file read /bin/bash
file read/write /dev/tty
file read /usr/lib64/locale/locale-archive
file read /etc/nsswitch.conf
file read /etc/passwd
file ioctl devpts:/3 0x540F
file read /lib64/rc/sh/openrc-run.sh
file read /lib64/rc/sh/functions.sh
file execute /lib64/rc/bin/eval_ecolors exec.realpath="/lib64/rc/bin/eval_ecolors" exec.argv[0]="eval_ecolors"
misc env PWD
misc env SHLVL
misc env _
file read /usr/share/terminfo/r/rxvt-unicode-256color
file ioctl devpts:/3 0x5413
file read /lib64/rc/sh/rc-functions.sh
file read /lib64/rc/sh/rc-cgroup.sh
file read /etc/conf.d/ntpd
file read /lib64/rc/sh/runit.sh
file read /lib64/rc/sh/s6.sh
file read /lib64/rc/sh/start-stop-daemon.sh
file read /lib64/rc/sh/supervise-daemon.sh
file write/truncate /sys/fs/cgroup/cpu/tasks
file write/truncate /sys/fs/cgroup/cpuacct/tasks
file write/truncate /sys/fs/cgroup/cpuset/tasks
file write/truncate /sys/fs/cgroup/freezer/tasks
file write/truncate /sys/fs/cgroup/memory/tasks
file write/truncate /sys/fs/cgroup/openrc/tasks
file execute /bin/mkdir exec.realpath="/bin/mkdir" exec.argv[0]="mkdir"
misc env RC_SERVICE
misc env SVCNAME
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0700
file write/truncate /sys/fs/cgroup/openrc/ntpd/tasks
file read /etc/init.d/ntpd
file execute /lib64/rc/bin/ebegin exec.realpath="/lib64/rc/bin/ebegin" exec.argv[0]="ebegin"
file execute /sbin/start-stop-daemon exec.realpath="/sbin/start-stop-daemon" exec.argv[0]="start-stop-daemon"
file read/write /dev/null
file ioctl /dev/tty 0x5422
file execute /usr/sbin/ntpd exec.realpath="/usr/sbin/ntpd" exec.argv[0]="/usr/sbin/ntpd"
file read /usr/lib64/gcc/x86_64-pc-linux-gnu/6.3.0/libgcc_s.so.1
network unix dgram send /dev/log
file mkdir /run/openrc/daemons/ntpd/ 0755
file create /run/openrc/daemons/ntpd/001 0666
file read/write/unlink /run/openrc/daemons/ntpd/001
file execute /lib64/rc/bin/eend exec.realpath="/lib64/rc/bin/eend" exec.argv[0]="eend"
file execute /lib64/rc/bin/service_set_value exec.realpath="/lib64/rc/bin/service_set_value" exec.argv[0]="service_set_value"
file read /etc/services
file read /etc/host.conf
file read /etc/resolv.conf
file read /etc/hosts
file create /run/ntpd.pid 0666
file read/write/unlink /run/ntpd.pid
file mkdir /run/openrc/options/ntpd/ 0755
file read /etc/ntp.conf
file create /run/openrc/options/ntpd/command 0666
file read/write/unlink /run/openrc/options/ntpd/command
file ioctl socket:[family=1:type=2:protocol=0] 0x8933
file create /run/openrc/options/ntpd/pidfile 0666
file read/write/unlink /run/openrc/options/ntpd/pidfile
file symlink /run/openrc/started/ntpd symlink.target="/etc/init.d/ntpd"
file unlink /run/openrc/starting/ntpd
file symlink /run/openrc/stopping/ntpd symlink.target="/etc/init.d/ntpd"
file unlink /run/openrc/started/ntpd
file execute /lib64/rc/bin/service_get_value exec.realpath="/lib64/rc/bin/service_get_value" exec.argv[0]="service_get_value"
file unlink /run/openrc/stopping/ntpd
file rmdir /run/openrc/options/ntpd/
file rmdir /run/openrc/daemons/ntpd/
network inet dgram bind/send @ALLIPV6 123
network inet dgram bind/send @ALLIPV4 123
file ioctl socket:[family=2:type=2:protocol=17] 0x541B
file read /etc/gai.conf
network inet dgram send 127.0.0.1 53
misc env *
misc env \*
file ioctl /dev/console 0x540F
file ioctl /dev/console 0x5413
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0755
file read/write /dev/console
file read /etc/terminfo/l/linux

I need to remove all the profiles with use_profile 0 and use_group 0 using a bash script or any kind of script I can run on a linux system. I've toyed around with awk,grep, and sed but I haven't made any progress.

I need to turn the above in to the below. Any tips, advice on what tools to use, or flat out showing me how would be much appreciated.

<kernel> /usr/sbin/ntpdate
use_profile 3
use_group 0

misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
misc env TERM
misc env XAUTHORITY
misc env PATH
misc env COLORTERM
misc env MAIL
misc env LOGNAME
misc env USER
misc env USERNAME
misc env HOME
misc env SHELL
misc env SUDO_COMMAND
misc env SUDO_USER
misc env SUDO_UID
misc env SUDO_GID
network unix dgram send /dev/log
file read /etc/nsswitch.conf
file read /etc/services
file read /etc/host.conf
file read /etc/resolv.conf
file read /etc/hosts
network inet dgram send 127.0.0.1 53
file ioctl socket:[family=2:type=2:protocol=17] 0x541B
file read /etc/gai.conf
network inet dgram bind/send :: 123
network inet dgram bind/send 0.0.0.0 123

<kernel> /etc/init.d/ntpd
use_profile 3
use_group 0

misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
misc env TERM
misc env XAUTHORITY
misc env PATH
misc env COLORTERM
misc env MAIL
misc env LOGNAME
misc env USER
misc env USERNAME
misc env HOME
misc env SHELL
misc env SUDO_COMMAND
misc env SUDO_USER
misc env SUDO_UID
misc env SUDO_GID
file read /sbin/openrc-run
file read /etc/rc.conf
file read proc:/cmdline
file read /etc/profile.env
file read proc:/cpuinfo
file read proc:/1/environ
file read /run/openrc/softlevel
file create /run/openrc/exclusive/ntpd 0664
file write/unlink /run/openrc/exclusive/ntpd
file symlink /run/openrc/starting/ntpd symlink.target="/etc/init.d/ntpd"
file read /run/openrc/depconfig
file read /run/openrc/deptree
file execute /lib64/rc/sh/openrc-run.sh exec.realpath="/lib64/rc/sh/openrc-run.sh" exec.argv[0]="/lib64/rc/sh/openrc-run.sh"
misc env CONFIG_PROTECT
misc env CONFIG_PROTECT_MASK
misc env GCC_SPECS
misc env GSETTINGS_BACKEND
misc env INFOPATH
misc env LESS
misc env LESSOPEN
misc env MANPAGER
misc env MANPATH
misc env OPENGL_PROFILE
misc env QT_GRAPHICSSYSTEM
misc env ROOTPATH
misc env VBOX_APP_HOME
misc env XDG_CONFIG_DIRS
misc env XDG_DATA_DIRS
misc env RC_VERSION
misc env RC_LIBEXECDIR
misc env RC_SVCDIR
misc env RC_TMPDIR
misc env RC_BOOTLEVEL
misc env RC_RUNLEVEL
misc env RC_DEFAULTLEVEL
misc env RC_UNAME
misc env EINFO_LOG
misc env RC_SVCNAME
misc env RC_OPENRC_PID
misc env RC_RUNSCRIPT_PID
misc env RC_CMD
file read /bin/bash
file read/write /dev/tty
file read /usr/lib64/locale/locale-archive
file read /etc/nsswitch.conf
file read /etc/passwd
file ioctl devpts:/3 0x540F
file read /lib64/rc/sh/openrc-run.sh
file read /lib64/rc/sh/functions.sh
file execute /lib64/rc/bin/eval_ecolors exec.realpath="/lib64/rc/bin/eval_ecolors" exec.argv[0]="eval_ecolors"
misc env PWD
misc env SHLVL
misc env _
file read /usr/share/terminfo/r/rxvt-unicode-256color
file ioctl devpts:/3 0x5413
file read /lib64/rc/sh/rc-functions.sh
file read /lib64/rc/sh/rc-cgroup.sh
file read /etc/conf.d/ntpd
file read /lib64/rc/sh/runit.sh
file read /lib64/rc/sh/s6.sh
file read /lib64/rc/sh/start-stop-daemon.sh
file read /lib64/rc/sh/supervise-daemon.sh
file write/truncate /sys/fs/cgroup/cpu/tasks
file write/truncate /sys/fs/cgroup/cpuacct/tasks
file write/truncate /sys/fs/cgroup/cpuset/tasks
file write/truncate /sys/fs/cgroup/freezer/tasks
file write/truncate /sys/fs/cgroup/memory/tasks
file write/truncate /sys/fs/cgroup/openrc/tasks
file execute /bin/mkdir exec.realpath="/bin/mkdir" exec.argv[0]="mkdir"
misc env RC_SERVICE
misc env SVCNAME
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0700
file write/truncate /sys/fs/cgroup/openrc/ntpd/tasks
file read /etc/init.d/ntpd
file execute /lib64/rc/bin/ebegin exec.realpath="/lib64/rc/bin/ebegin" exec.argv[0]="ebegin"
file execute /sbin/start-stop-daemon exec.realpath="/sbin/start-stop-daemon" exec.argv[0]="start-stop-daemon"
file read/write /dev/null
file ioctl /dev/tty 0x5422
file execute /usr/sbin/ntpd exec.realpath="/usr/sbin/ntpd" exec.argv[0]="/usr/sbin/ntpd"
file read /usr/lib64/gcc/x86_64-pc-linux-gnu/6.3.0/libgcc_s.so.1
network unix dgram send /dev/log
file mkdir /run/openrc/daemons/ntpd/ 0755
file create /run/openrc/daemons/ntpd/001 0666
file read/write/unlink /run/openrc/daemons/ntpd/001
file execute /lib64/rc/bin/eend exec.realpath="/lib64/rc/bin/eend" exec.argv[0]="eend"
file execute /lib64/rc/bin/service_set_value exec.realpath="/lib64/rc/bin/service_set_value" exec.argv[0]="service_set_value"
file read /etc/services
file read /etc/host.conf
file read /etc/resolv.conf
file read /etc/hosts
file create /run/ntpd.pid 0666
file read/write/unlink /run/ntpd.pid
file mkdir /run/openrc/options/ntpd/ 0755
file read /etc/ntp.conf
file create /run/openrc/options/ntpd/command 0666
file read/write/unlink /run/openrc/options/ntpd/command
file ioctl socket:[family=1:type=2:protocol=0] 0x8933
file create /run/openrc/options/ntpd/pidfile 0666
file read/write/unlink /run/openrc/options/ntpd/pidfile
file symlink /run/openrc/started/ntpd symlink.target="/etc/init.d/ntpd"
file unlink /run/openrc/starting/ntpd
file symlink /run/openrc/stopping/ntpd symlink.target="/etc/init.d/ntpd"
file unlink /run/openrc/started/ntpd
file execute /lib64/rc/bin/service_get_value exec.realpath="/lib64/rc/bin/service_get_value" exec.argv[0]="service_get_value"
file unlink /run/openrc/stopping/ntpd
file rmdir /run/openrc/options/ntpd/
file rmdir /run/openrc/daemons/ntpd/
network inet dgram bind/send @ALLIPV6 123
network inet dgram bind/send @ALLIPV4 123
file ioctl socket:[family=2:type=2:protocol=17] 0x541B
file read /etc/gai.conf
network inet dgram send 127.0.0.1 53
misc env *
misc env \*
file ioctl /dev/console 0x540F
file ioctl /dev/console 0x5413
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0755
file read/write /dev/console
file read /etc/terminfo/l/linux
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

2 Answers2

2

Your question is very similar to Print entire paragraph in a file on pattern match only that in your case it's sections of text delimited by <kernel>... and you want the opposite (i.e. delete the section that matches) . You could adapt any of the solutions there to your needs, e.g. with sed:

sed '/<kernel>/!{H;$!d;};x;/\nuse_profile 0\nuse_group 0\n/d' infile

or, if your sed doesn't like that syntax:

sed -e '/<kernel>/!{H;$!d' -e '}' -e 'x;/\nuse_profile 0\nuse_group 0\n/d' infile
don_crissti
  • 82,805
0

awk approach:

awk 'BEGIN{fn="use_profile_output";}/<kernel>/{getline up; if(up~/use_profile [1-9][0-9]*/)
     {f=1; print $0 RS up > fn; next }else{ f=0 }}{ if(f) print > fn; }' file

fn="use_profile_output" - fn(file name) variable containing use_profile_output as the resulting file name for all <kernel> blocks containing use_profile without followed zero 0

/<kernel>/ - on each encountering a line containing <kernel> keyword the followed set of braces will be executed

getline up; - gets the next record containing use_profile keyword and assign it to the variable up


use_profile_output file contents (some lines were omitted to show compact output):

<kernel> /usr/sbin/ntpdate
use_profile 3
use_group 0

misc env LS_COLORS
misc env LANG
misc env DISPLAY
misc env LC_CTYPE
...
...
network inet dgram bind/send :: 123
network inet dgram bind/send 0.0.0.0 123



<kernel> /etc/init.d/ntpd
use_profile 3
use_group 0

misc env LS_COLORS
misc env LANG
...
...
misc env *
misc env \*
file ioctl /dev/console 0x540F
file ioctl /dev/console 0x5413
file mkdir /sys/fs/cgroup/openrc/ntpd/ 0755
file read/write /dev/console
file read /etc/terminfo/l/linux