Utah Tech Logo

IT3300

DevOps virtualization

Lab 14

In this assignment you will develop some simple bash shell scripts to allow you to automate repetetive tasks. You will also review other shell commands.

Part I

Begin by developing a shell script that will search for files within a directory whose name contains a space. Your script should replace all spaces in a filename with an underscore.

Here is some pseudocode to help you solve this:

  1. loop through all the files in the directory
  2. grep for space in the filename
  3. capture results of grep operation ($?)
  4. Do an if test to see if it did have a space
  5. If it did, echo the filname out and use sed to replace spaces with underscores.
  6. Use mv command to rename file
  7. Maybe echo out a nice message to the user
  8. End if, end loop
Part II

Write a shell script that will read some lines of an input file which contains host names of various machines (see here). Note that you will have to parse the file to pull out the hostnames. This example could help you get started. Note that when you run the script it may try to ssh into the different hosts. To make it so it doesn’t prompt you for a password for each machine, you should do something like ssh-copy-id oxygen before running the script. You may have to answer ‘yes’ to connect to each host the first time you run the script.

If the 119 file doesn’t have many responsive hosts, you could also try this file.

Your script should ssh to the machines in question and gather the following pieces of information:

  1. A count as to how many users are currently logged in (use the who command with some other commands to find the count)
  2. The current memory utilization. (use the free command and capture the total memory and the free memory)

Your script should create a new file for each machine that has the above information in it. The filename should be something like krypton_stats.txt where krypton is the name of the host. The filename should only be created if the host actually responds to a ping.

The content of the file you create should have the format that looks like this:

    1545 megabytes of memory out of 7893 are available
    There are 2 users currently logged in 
To pass off

This will be passed off in class. You will run your script and show me that it works.