============================== Shell Loops and Menus exercise ============================== - Prepared by Ian Allen - idallen@ncf.ca Work along with your instructor solving the following problem: "You have some friends who need help staying awake while they work on their Unix homework. You volunteer to help keep them awake by sending them inter-terminal messages using the Unix "write" command. You arrange with each different friend what message they would like to see on their screen. To make your life easier, you write a menu program that remembers the message for each of your friends. You type in the name; the script picks the correct message and sends it." Work with your instructor to build this script: 1) Login twice to ACADAIX, using telnet in two Floppix consoles or using two Windows telnet sessions. (Read the "Using Telnet" web page before you use the Windows telnet program to a Unix system!) Only ACADAIX has the Unix "banner" command we need for this script. 2) Send yourself a message using "write", e.g. "date | write $USER". Make a note of which telnet window receives the output of "write". Work in the *other* window while we write this script. The window receiving the "write" output will be receiving all kinds of messages; you won't be able to work in it. Use the non-write window. 3) Test the "banner" command. Try this: $ banner Hello There! You should see the words Hello There! in big letters on your screen. Now, pipe the output of banner into write to your other window: $ banner Hello There! | write $USER You should see the big letters appear in your other telnet window. 4) Pick two or three people in the room to whom you will be sending wake-up messages. Find out their names and Unix userids and what short message they would like you to send to their screens. (The banner command output doesn't look good unless you keep your banners to a few words.) 5) Write a looping menu script (similar to the one on p.390 in Chapter 11) that prompts you for the name or userid of your friend and then sends him/her the appropriate banner message using the "write" command. The script might look like this in operation: $ ./wakeup Enter the name: billy You entered: billy Writing "Wakie! Wakie!" to "billy" (userid abcd0001). Message written to abcd0001. Enter the name: bessie You entered: bessie Writing "Yo! Wazup!" to "bessie" (userid abcd0002). Message written to abcd0002. Enter the name: becky You entered: becky Writing "Moo! Moo!" to "becky" (userid abcd0003). write: 0803-025 abcd0003 is not logged on. Error 255 ocurred writing to abcd0003. Enter the name: nosuch You entered: nosuch ./wakeup: Unrecognized input "nosuch" Please enter a recognized name. Valid names are: me billy bessie becky Enter the name: q You entered: q Quitting the script - bye now! 6) Test your script with your two or three volunteers. Try shell special characters in the input, to make sure you have quoted all your variables correctly.