1.5 KiB
1.5 KiB
LPIC-1 105.2: Writing simple scripts
Tests and exit codes, a script that mails root, loops and case.
Before you start
The lab puts the chapter's diskcheck script in
/usr/local/sbin/diskcheck. It sets aside root's mailbox, if there is
one, so the check sees only new mail. Write your scripts in /root, start
each with a #! line, and make them executable.
Tasks
- Write
/root/checkfiles.sh, which takes any number of file names and prints one line for each: the name and whether it'smissing, adirectoryor areadablefile. It exits with status 1 if any were missing, and 0 otherwise. - Install a mail client and a local MTA (Postfix), then run
/usr/local/sbin/diskcheck 5as root and read root's mail. - Write
/root/count.sh, which prints the numbers 1 to 10, one per line, with awhileloop and a counter (the chapter'sfor i in $(seq 1 10)rewritten). - Write
/root/service.sh, acasescript that acceptsstart,stopandstatus(printing what it would do), and prints a usage message for anything else, including no argument.
Hints
"$@",[ -e ],[ -d ],[ -r ],exit 1; test withecho $?.- The mail client is
s-nailon the RHEL family andmailutilson Debian and Ubuntu; it gives youmail. Postfix needs to be running.mailwith no arguments reads your mailbox. i=1,while [ "$i" -le 10 ],i=$((i + 1)).case "$1" in start) ... ;; *) echo "usage: ..." ;; esac; thenbash -x /root/service.sh startto follow it step by step.