Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

9.9. Exercises

Remember: when building scripts, work in steps and test each step before incorporating it in your script.

  1. Create a script that will take a (recursive) copy of files in /etc so that a beginning system administrator can edit files without fear.

  2. Write a script that takes exactly one argument, a directory name. If the number of arguments is more or less than one, print a usage message. If the argument is not a directory, print another message. For the given directory, print the five biggest files and the five files that were most recently modified.

  3. Can you explain why it is so important to put the variables in between double quotes in the example from Section 9.4.2?

  4. Write a script similar to the one in Section 9.5.1, but think of a way of quitting after the user has executed 3 loops.

  5. Think of a better solution than move -b for the script from Section 9.5.3 to prevent overwriting of existing files. For instance, test whether or not a file exists. Don't do unnecessary work!

  6. Rewrite the whichdaemon.sh script from Section 7.2.4, so that it:

    • Prints a list of servers to check, such as Apache, the SSH server, the NTP daemon, a name daemon, a power management daemon, and so on.

    • For each choice the user can make, print some sensible information, like the name of the web server, NTP trace information, and so on.

    • Optionally, build in a possibility for users to check other servers than the ones listed. For such cases, check that at least the given process is running.

    • Review the script from Section 9.2.2.4. Note how character input other than q is processed. Rebuild this script so that it prints a message if characters are given as input.

 
 
  Published under the terms of the GNU General Public License Design by Interspire