In this lab, you 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 servera machine as the student user and switch to the root user.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Use the grep command to find the GID and UID for the postfix and postdrop groups and users.
To do so, use the rpm -q --scripts command, 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/usr/sbin/groupadd-g 90 -rpostdrop2>/dev/null/usr/sbin/groupadd-g 89 -rpostfix2>/dev/null/usr/sbin/groupadd-g 12 -r/usr/sbin/useradd-d /var/spool/postfix -s /sbin/nologin -g postfix -G mail -M -r -u 89postfix2>/dev/null setgid_group=postdrop \
Modify the previous regular expression to display the first two messages in the /var/log/maillog file.
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 2
Apr 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 queue directory for the Postfix server.
Search the /etc/postfix/main.cf configuration file for all information about queues.
Use the grep command -i option 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 postfix service writes messages to the /var/log/messages file.
Use the less command 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 the less command.
[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 aux command to confirm that the postfix server is currently running.
Use the grep command 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=autopostfix
Confirm that the qmgr, cleanup, and pickup queues are correctly configured. Use the grep command -e option to match multiple entries in the same file. The /etc/postfix/master.cf file 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 1oqmgr
Return to the workstation machine as the student user.
[root@servera ~]#exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
This concludes the section.