RHCSA 3.1: Conditions and tests
Scripts that test files, the user running them, whether a user exists, and whether a service is running.
Before you start
Write each script where its task says, and make it executable by
everyone. The checks run your scripts, as root and as an unprivileged
user; the check for task 4 stops chronyd first and starts it again
afterwards if your script didn't.
Tasks
- Write
/usr/local/bin/kindthat printsfile,directoryormissingfor the path given as its first argument. - Write
/usr/local/bin/amirootthat printsrootand exits 0 when run as root, and printsnot rootand exits 1 otherwise. - Write
/usr/local/bin/userexiststhat takes a user name and prints whether that user exists:NAME existsorNAME does not exist. - Write
/usr/local/bin/start-chronydthat startschronydif it isn't running and does nothing otherwise (it prints nothing then).
Hints
[ -d ],[ -f ],[ -e ];if,elif,else,fi.id -uis 0 for root, or$EUID;exit 1.id NAME >/dev/null 2>&1orgetent passwd NAME.systemctl is-active --quiet chronyd || systemctl start chronyd.- Start each script with
#!/bin/bash;chmod 755.