You are on page 1of 1

Practice Exercises - Case Statements

Exercise 1:

Createastartupscriptforanapplicationcalledsleepwalkingserver,whichisprovidedbelow.
Thescriptshouldbenamedsleepwalkingandaccept"start"and"stop"asarguments.If
anythingotherthan"start"or"stop"isprovidedasanargument,displayausagestatement:
"Usagesleepwalkingstart|stop"andterminatethescriptwithanexitstatusof1.

Tostartsleepwalkingserver,usethiscommand:"/tmp/sleepwalkingserver&"

Tostopsleepwalkingserver,usethiscommand:"kill$(cat/tmp/sleepwalkingserver.pid)"

Hereisthecontentsof"sleepwalkingserver".Besuretoputthisfilein/tmpandrunchmod
755/tmp/sleepwalkingserver

#!/bin/bash
PID_FILE="/tmp/sleepwalkingserver.pid"
trap"rm$PID_FILEexit"SIGHUPSIGINTSIGTERM
echo"$$">$PID_FILE

whiletrue
do
:
done

LinuxTrainingAcademy.com

You might also like