Linux awk command bulk shutdown system boot-up service

Source: Internet
Author: User

After installing a new system, some boot-start services need to be shut down in order to simplify the system.

The snail uses the basic commands of grep and awk to operate.

As a server, the service that needs to be started in the new system is probably the following

Crond Network sshd Rsyslog


Viewing runlevel 3 boot-up services

Chkconfig--list|grep 3:on

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/A4/3E/wKioL1mnaRKSUKGBAACJJTszOTk109.png-wh_500x0-wm_ 3-wmp_4-s_319818434.png "style=" Float:none; "title=" Image.png "alt=" wkiol1mnarksukgbaacjjtszotk109.png-wh_50 "/ >

Step 1: Collect the service name

Use grep to filter out the 3:on service, then exclude the four options for Crond network sshd rsyslog, then utility awk outputs the first column of content

Chkconfig--list|grep 3:on|grep-ev "Network|sshd|crond|rsyslog" |awk ' {print $} '


650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/A4/3E/wKioL1mnaRKy2axEAAA-Hozzx5k703.png-wh_500x0-wm_ 3-wmp_4-s_1109712849.png "style=" Float:none; "title=" Image1.png "alt=" wkiol1mnarky2axeaaa-hozzx5k703.png-wh_50 "/ >

Here's a practical awk-based operation, which describes one of awk's parameters-F after adding a field delimiter to use after using fields like $ $ $ and so on to filter if you don't use the-F default delimiter as a space, the above operation directly uses the contents of the output after

The whole row is the first column.

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/05/8D/wKiom1mnaSiQretSAAOe73sJOsQ025.png-wh_500x0-wm_ 3-wmp_4-s_2952377833.png "style=" Float:none; "title=" Image2.png "alt=" wkiom1mnasiqretsaaoe73sjosq025.png-wh_50 "/ >

Step 2: Combine the captured data into a command and bash

Chkconfig--list|grep 3:on|grep-ev "Network|sshd|crond|rsyslog" |awk ' {print $} ' |awk ' {print ' chkconfig ' $ ' off '} ' |bas H

It is important to note that the trailing and off of the chkconfig must be preceded by a space that is combined with the awk variable and sent to bash for processing


The operation results are as follows

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/05/8D/wKiom1mnaSnAyCeFAAA7ufic8yY717.png-wh_500x0-wm_ 3-wmp_4-s_1618460001.png "style=" Float:none; "title=" Image4.png "alt=" wkiom1mnasnaycefaaa7ufic8yy717.png-wh_50 "/ >

It's just a simple practical way to use Awk's other powerful features and continue writing ...

This article is from the "relentless snail" blog, please be sure to keep this source http://songxiao.blog.51cto.com/12183698/1961289

Linux awk command bulk shutdown system boot-up service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.