0% found this document useful (0 votes)
125 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 "/tmp/sleep-walking-server &" and to stop it, run "kill $(cat /tmp/sleep-walking-server.pid)". It also provides the contents of the "sleep-walking-server" file to put in /tmp.

Uploaded by

zahed83
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)
125 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 "/tmp/sleep-walking-server &" and to stop it, run "kill $(cat /tmp/sleep-walking-server.pid)". It also provides the contents of the "sleep-walking-server" file to put in /tmp.

Uploaded by

zahed83
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:
 
Create a startup script for an application called sleep­walking­server, which is provided below. 
The script should be named sleep­walking and accept "start" and "stop" as arguments.  If 
anything other than "start" or "stop" is provided as an argument, display a usage statement: 
"Usage sleep­walking start|stop" and terminate the script with an exit status of 1. 
 
To start sleep­walking­server, use this command: "/tmp/sleep­walking­server &" 
 
To stop sleep­walking­server, use this command: "kill $(cat /tmp/sleep­walking­server.pid)" 
 
Here is the contents of "sleep­walking­server".  Be sure to put this file in /tmp and run chmod 
755 /tmp/sleep­walking­server 
 
#!/bin/bash 
PID_FILE="/tmp/sleep­walking­server.pid" 
trap "rm $PID_FILE; exit" SIGHUP SIGINT SIGTERM 
echo "$$" > $PID_FILE 
 
while true 
do 
  : 
done 
 

 
 
 
 
 

LinuxTrainingAcademy.com 

You might also like