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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Jones,Bill,235 S. Williams St.,Denver,CO,80221,(303) 244−7989<br />

Smith,Tom,404 Polk Ave.,Los Angeles,CA,90003,(213) 879−5612<br />

...<br />

Reformat the data and print it out to stdout in labeled, evenly−spaced columns.<br />

Justification<br />

Given ASCII text input either from stdin or a file, by adjusting the word spacing right−justify each<br />

line to a user−specified line−width and send the output to stdout.<br />

Mailing List<br />

Using the mail command, write a script that manages a simple mailing list. The script automatically<br />

e−mails the monthly company newsletter, read from a specified text file, and sends it to all the<br />

addresses on the mailing list, which the script reads from another specified file.<br />

Passwords<br />

Generate pseudorandom 8−character passwords, using characters in the ranges [0−9], [A−Z], [a−z].<br />

Each password must contain at least two digits.<br />

Difficult<br />

Logging File Accesses<br />

Log all accesses to the files in /etc during the course of a single day. This information should<br />

include the filename, user name, and access time. If any alterations to the files take place, that should<br />

be flagged. Write this data as neatly formatted records in a logfile.<br />

Strip Comments<br />

Strip all comments from a shell script whose name is specified on the command line. Note that the "#!<br />

line" must not be stripped out.<br />

HTML Conversion<br />

Convert a given text file to HTML. This non−interactive script automatically inserts all appropriate<br />

HTML tags into a file specified as an argument.<br />

Strip HTML Tags<br />

Strip all HTML tags from a specified HTML file, then reformat it into lines between 60 and 75<br />

characters in length. Reset paragraph and block spacing, as appropriate, and convert HTML tables to<br />

their approximate text equivalent.<br />

XML Conversion<br />

Convert an XML file to both HTML and text format.<br />

Chasing Spammers<br />

Write a script that analyzes a spam e−mail by doing DNS lookups on the IP addresses in the headers<br />

to identify the relay hosts as well as the originating ISP. The script will forward the unaltered spam<br />

message to the responsible ISPs. Of course, it will be necessary to filter out your own ISP's IP<br />

address, so you don't end up complaining about yourself.<br />

As necessary, use the appropriate network analysis commands.<br />

Morse Code<br />

Convert a text file to Morse code. Each character of the text file will be represented as a<br />

corresponding Morse code group of dots and dashes (underscores), separated by whitespace from the<br />

next. For example, "script" ===> "... _._. ._. .. .__. _".<br />

Hex Dump<br />

Do a hex(adecimal) dump on a binary file specified as an argument. The output should be in neat<br />

tabular fields, with the first field showing the address, each of the next 8 fields a 4−byte hex number,<br />

and the final field the ASCII equivalent of the previous 8 fields.<br />

Emulating a Shift Register<br />

Appendix I. Exercises 436

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

Saved successfully!

Ooh no, something went wrong!