0% found this document useful (0 votes)
17 views1 page

Practice Exercises - Case Statements: Exercise 1

This document provides an exercise to create a script called "sleep-walking" that accepts "start" and "stop" arguments. If any other argument is passed, it should display a usage statement and exit with a status of 1. To start the "sleep-walking-server", the script should run a provided command. To stop it, it should run a kill command targeting the server's process ID stored in a PID file.

Uploaded by

Saurabh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Practice Exercises - Case Statements: Exercise 1

This document provides an exercise to create a script called "sleep-walking" that accepts "start" and "stop" arguments. If any other argument is passed, it should display a usage statement and exit with a status of 1. To start the "sleep-walking-server", the script should run a provided command. To stop it, it should run a kill command targeting the server's process ID stored in a PID file.

Uploaded by

Saurabh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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