Skip to main content

Practice Test 03

Updated Apr 22, 2021 ·

Lab 01 - Checking Jobs

Tasks:

  1. Determine when will the following jobs run:

    00 07 25 12 * /root/backup.sh
    */5 * * * * /root/take_stats.sh
    07 03 * * * /root/email_check.sh
    30 16 * * 5 /root/check_server.sh
    00 00 * * 1-5 /root/check_server.sh
Solution

Answer:

/root/backup.sh will run at 7 AM on Christmas Day(25th of December)
/root/take_stats.sh will run every 5 minutes
/root/email_check.sh will run every day at 3:07 AM
/root/check_server.sh will run every Friday at 4:30 PM
/root/check_server.sh will run at midnight on all weekdays(M,Tu,W,Th,F)
Note:

Reference:

fieldallowed values
minute0-59
hour0-23
day of month1-31
month1-12 (or names, see below)
day of week0-7 (0 or 7 is Sun, or use names)

Lab 02 - Creating Jobs

Tasks:

  1. What command shows all of user ted’s scheduled jobs?
  2. What command will allow root to setup a cron schedule for user ted to run the /bin/ls command every minute?
Solution

Show all of ted’s scheduled jobs:

sudo crontab -u ted -l

What command will allow root to setup a cron schedule for user ted to run the /bin/ls command every minute.

sudo crontab -u ted -e

Once you type the above command, a temporary file will be opened in vi. You will need to type the following line and just save the file.

* * * * * /bin/ls

Lab 03 - Users

Tasks:

  1. Print all usernames that begin with the letter r.
  2. Search usernames that begin with the letter k and store them in a file named /tmp/k_user_list.txt.
  3. Print all accounts whose shells (last column) are /sbin/nologin.
Solution

Print all usernames that begin with the letter r.

grep "^r" /etc/passwd 

Search usernames that begin with the letter k and store them in a file named /tmp/k_user_list.txt

grep "^k" /etc/passwd > /tmp/k_user_list.txt  

Print all accounts whose shells (last column) are /sbin/nologin

grep "/sbin/nologin$" /etc/passwd 

Lab 04 - Files

Tasks:

  1. List all files in /usr/share/doc that end with the number four.
  2. Search all lines with the word 'Romeo' from file /tmp/romeo.txt and order them in a-z. These ordered lines should be stored in a new file named /tmp/new.txt
  3. Find all files named a.txt on eden’s home directory.
  4. Find all files on your system whose permission is 777.
  5. Find all files on your system whose owner is eden and redirect them to another file named /tmp/eden1.txt.
  6. Find all files on your system whose permission is 777 and change this permission to 700.
  7. Find all files on your system that are owned by user eden and copy these files in a directory named /tmp/edendir.
Solution

List all files in /usr/share/doc that end with the number four.

ls  /usr/share/doc | grep "4$"

Search all lines with the word 'Romeo' from file /tmp/romeo.txt and order them in a-z. These ordered lines should be stored in a new file named /tmp/new.txt

grep 'Romeo' /tmp/romeo.txt | sort > /tmp/new.txt

Find all files named a.txt on user eden’s home directory.

ls /home/eden | grep '^a.txt$'
find /home/eden -name 'a.txt' -print

Find all files on your system whose permission is 777.

find / -perm 777

Find all files on your system whose owner is user eden and redirect them to another file named /tmp/eden1.txt.

find / -user eden > /tmp/eden1.txt

Find all files on your system whose permission is 777 and change this permission to 700.

find / -perm 777 -exec chmod 700 {} 

Find all files on your system that are owned by user eden and copy these files in a directory named /tmp/edendir.

mkdir -p /tmp/edendir
find / -user eden -exec cp {} /tmp/edendir \;

Lab 05 - Grep

Tasks:

Find the rows that contain "mongodb" from file /usr/bin/app, and write it to the file /tmp/app-list.txt.

Solution
cat /usr/bin/app 
grep mongodb /usr/bin/app > /tmp/app-list.txt

Lab 06 - Autofs

Tasks:

Configure autofs to make sure after login successfully, it has the home directory autofs, which is shared as /home/ldapuser40 at the ip: 172.24.40.10. and it also requires that, other ldap users can use the home directory normally.

Solution
sudo su -

# check if autofs exist
ll /etc/auto*
systemctl status autofs

# if the autofs are not found, install autofs
yum search autofs
yum install -y autofs
ll /etc/auto*

# edit the files
cd /etc
ll
vim auto.master
/home /etc/auto.ldap
vim auto.ldap
/home/ldapuser40 -rw,soft,intr 172.24.40.10:/home/ldapuser40

# restart autofs
systemctl restart autofs
systemctl status autofs
showmount -e 172.24.40.10

# verify by loggin-in using the user
su - ldapuser40

Lab 07 - LVM

Tasks:

  1. Create logical volume ‘lv1’ with volume group ‘group’.
  2. The logical volume ‘lv1’ should be of size 60.
  3. PE size should be 4 mb .
  4. Filesystem type is ext4. This logical volume must be mounted at /mnt/redhat.
  5. Extend by 10M.
Solution
sudo su -
# create partition first, if created, proceed
sudo fdisk /dev/xxx
pvcreate /dev/xxx1
pvs
vgcreate -s 4 group /dev/xxx1
vgs
lvcreate -l 60 -n lv1 group
lvs
mkfs.ext4 /dev/group/lv1

mkdir -p /mnt/redhat
vim /etc/fstab
/dev/group/lv1 /mnt/redhat xfs defaults 0 0
:wq!
lsblk
mount -a
lsblk
lsblk -f
lvextend -l +10 /dev/group/lv1
resize2fs /dev/group/lv1
lsblk

Lab 08 - Users and Groups

Tasks:

  1. Create the following users and groups with appropriate password assignments.
  2. Make sure that you force the users to change their password on the first logon.
GroupsUsersPassword
devteamTom, Pete, Vince, JohnP@$$w0rdabc123
devleadJames, BenP@$$w0rdxyz246
Solution

Create the groups and users.

# Create groups
sudo su -
groupadd devteam
groupadd devlead

# Create users and add to respective groups
useradd -G devteam tom
useradd -G devteam pete
useradd -G devteam vince
useradd -G devteam kiran
useradd -G devlead james
useradd -G devlead ben

# Set passwords for users
echo 'P@$$w0rdabc123' | passwd --stdin tom
echo 'P@$$w0rdabc123' | passwd --stdin pete
echo 'P@$$w0rdabc123' | passwd --stdin vince
echo 'P@$$w0rdabc123' | passwd --stdin kiran
echo 'P@$$w0rdxyz246' | passwd --stdin james
echo 'P@$$w0rdxyz246' | passwd --stdin ben

# Force users to change passwords on next login
chage -d 0 tom
chage -d 0 pete
chage -d 0 vince
chage -d 0 kiran
chage -d 0 james
chage -d 0 ben

Lab 09 - Cron

Tasks:

  1. Build a shell script to take a backup of the /etc/directory every night using the tar command.
  2. The backup script should be named as /root/backup.sh.
  3. Schedule this script to run at 11:00 PM every night – except Sundays.
Solution

Create the script.

#!/bin/bash

# /root/backup.sh
# Backups /etc every night, except on Sundays

tar -czvf /etc/directory.bak.tar.gz /etc/dir

Add the cron schedule.

crontab -e  
* 21 * * 1-6  /root/backup.sh
chmod +x /root/backup.sh

Lab 10 - Permissions

Tasks:

  1. No users should be able to read the file "app-license.pdf" other than the users from the “devteam” group.
  2. It is assumed that root can read any files.
Solution
chown root:devteam app-license.pdf
chmod 640 app-license.pdf