Homework #5

Due: 1:30 PM, 8 December, 1994

Write C shell scripts to solve the following six familiar problems and send me email telling me where you saved the scripts. These scripts should work flawlessly!

Problem 1

Write a C shell script that prompts for an hour of the day. The hour should be entered as a number between 0 and 23. Your shell script should then print out the last time you logged into the workstation during that hour.

Problem 2

Write a C shell script that prints out all the times you were logged into your present workstation during the months of June, July, and August.

Problem 3

Write a C shell script that displays the last ten times you were logged into your present workstation.

Problem 4

Write a C shell script that calculates the number of minutes you were logged into your present workstation on your last complete (login and logout) session. Your program should work even if you were logged into the system more than one whole day.

Problem 5

Write a C shell script that takes a Unix directory name as an argument. The shell script then checks if that directory has any files named moe, larry, or curly. If any of these files exist, the script prints out a useful message. For example, assume the directory /stooges contains files moe and curly, but not larry. If you run your shell script by typing

        checkfiles /stooges

the script should print something like

        moe is a file
        curly is a file

Problem 6

Write a C shell script that takes a Unix pathname as an argument. The shell script then prints a message that states if the pathname is a directory or not. For example, typing

        isadir /etc

should result in the message

        /etc is a directory

while typing

        isadir /etc/passwd

should result in the message

        /etc/passwd is not a directory

Back to the Handout index