27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

done<br />

# Bring the subsystem down.<br />

if [ −f /etc/rc.d/init.d/$subsys.init ]; then<br />

/etc/rc.d/init.d/$subsys.init stop<br />

else<br />

/etc/rc.d/init.d/$subsys stop<br />

# −−> Suspend running jobs and daemons<br />

# −−> using the 'stop' shell builtin.<br />

fi<br />

That wasn't so bad. Aside from a little fancy footwork with variable matching, there is no new material there.<br />

Exercise 1. In /etc/rc.d/init.d, analyze the halt script. It is a bit longer than killall, but similar in<br />

concept. Make a copy of this script somewhere in your home directory and experiment with it (do not run it as<br />

root). Do a simulated run with the −vn flags (sh −vn scriptname). Add extensive comments. Change<br />

the "action" commands to "echos".<br />

Exercise 2. Look at some of the more complex scripts in /etc/rc.d/init.d. See if you can understand<br />

parts of them. Follow the above procedure to analyze them. For some additional insight, you might also<br />

examine the file sysvinitfiles in /usr/share/doc/initscripts−?.??, which is part of the<br />

"initscripts" documentation.<br />

Chapter 13. System and Administrative Commands 235

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!