Red Hat System Administration II
Search for text in the system logs and the output of commands to find information more efficiently.
Outcomes
Efficiently search for text in log files and configuration files.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that all required resources are available.
[student@workstation ~]$ lab start console-regex
Instructions
Log in to the
serveramachine as thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Use the
grepcommand to find the GID and UID for thepostfixandpostdropgroups and users. To do so, use therpm -q --scriptscommand, which queries the information for a specific package and shows the scripts that are used as part of the installation process.[root@servera ~]#
rpm -q --scripts postfix | grep -e 'user' -e 'group'# Add user and groups if necessary # generated from postfix.sysusers getent group 'postfix' >/dev/null || groupadd -f -g '89' -r 'postfix' || : useradd -r -u '89' -g 'postfix' -d '/var/spool/postfix' -s '/sbin/nologin' -c '' 'postfix' || : useradd -r -g 'postfix' -d '/var/spool/postfix' -s '/sbin/nologin' -c '' 'postfix' || : getent group 'postdrop' >/dev/null || groupadd -f -g '90' -r 'postdrop' || : getent group 'mail' >/dev/null || groupadd -f -g '12' -r 'mail' || : getent group 'mail' >/dev/null || groupadd -r 'mail' || : useradd -r -g 'postfix' -d '/' -s '/usr/sbin/nologin' -c '' 'postfix' || : if getent group 'mail' >/dev/null; then usermod -a -G 'mail' 'postfix' || : setgid_group=postdrop \Modify the previous regular expression to display the first two messages in the
/var/log/maillogfile. In this search, you do not need to use the caret character (^), because you are not searching for the first character in a line.[root@servera ~]#
grep 'postfix' /var/log/maillog | head -n 2Apr 1 15:27:16 servera postfix/postfix-script[3121]: starting the Postfix mail system Apr 1 15:27:16 servera postfix/master[3123]: daemon started -- version 3.5.9, configuration /etc/postfixFind the name of the
queuedirectory for thePostfixserver. Search the/etc/postfix/main.cfconfiguration file for all information about queues. Use thegrepcommand-ioption to ignore case distinctions.[root@servera ~]#
grep -i 'queue' /etc/postfix/main.cf# testing. When soft_bounce is enabled, mail will remain queued that # The queue_directory specifies the location of the Postfix queue. queue_directory = /var/spool/postfix # QUEUE AND PROCESS OWNERSHIP # The mail_owner parameter specifies the owner of the Postfix queue # is the Sendmail-compatible mail queue listing command. # setgid_group: The group for mail submission and queue managementConfirm that the
postfixservice writes messages to the/var/log/messagesfile. Use thelesscommand and then the slash character (/) to search the file. Press n to move to the next entry that matches the search. Press q to quit thelesscommand.[root@servera ~]#
less /var/log/messages...output omitted... Apr 1 15:27:15 servera systemd[1]: Starting Postfix Mail Transport Agent... ...output omitted... Apr 1 15:27:16 servera systemd[1]: Started Postfix Mail Transport Agent. ...output omitted... /PostfixUse the
ps auxcommand to confirm that thepostfixserver is currently running. Use thegrepcommand to limit the output to the necessary lines.[root@servera ~]#
ps aux | grep postfixroot 3123 0.0 0.2 38172 4384 ? Ss 15:27 0:00 /usr/libexec/postfix/master -wpostfix3124 0.0 0.4 45208 8236 ? S 15:27 0:00 pickup -l -t unix -upostfix3125 0.0 0.4 45252 8400 ? S 15:27 0:00 qmgr -l -t unix -u root 3228 0.0 0.1 221668 2288 pts/0 S+ 15:55 0:00 grep --color=autopostfixConfirm that the
qmgr,cleanup, andpickupqueues are correctly configured. Use thegrepcommand-eoption to match multiple entries in the same file. The/etc/postfix/master.cffile is the configuration file.[root@servera ~]#
grep -e qmgr -e pickup -e cleanup /etc/postfix/master.cfpickupunix n - n 60 1pickupcleanupunix n - n - 0cleanupqmgrunix n - n 300 1qmgr#qmgrunix n - n 300 1oqmgrReturn to the
workstationmachine as thestudentuser.[root@servera ~]#
exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$