Changes

Jump to: navigation, search

OPS435 Test1 Practice - Bash

2,240 bytes added, 13:41, 22 August 2017
m
You need to be able to write a short script using constructs and utilities we've discussed in the course so far. These exercises should be helpful to you as practice to reinforce what you already learned during the semester.
 
= Variables =
 
== Email Apache status ==
 
Write a script that will email the number of apache processes currently running to admin@yourdomain.com. The syntax of the '''mail''' command is:
 
<source lang="bash">mail admin@yourdomain.com -s "Your subject" "body of message"</source>
 
One line of the output of the '''ps''' command looks like this:
 
<source lang="bash"> 1030 ? Ssl 0:00 /usr/bin/apache</source>
 
You can get the current date with the '''date''' command.
 
Your script should count the number of apache processes running, and send the admin an email with a body like this: "There are now (2016-02-22 14:21) 3 apache processes running".
= Conditions =
Write a script that will check whether any interface has the IP address 10.0.0.4 and if it does - it will print the subnet mask used with that interface (subnet mask or bit length, whatever you prefer). If it doesn't - it will print a message saying so.
 
== Maybe start Apache ==
 
Write a script that will use the ps command to check whether any apache processes are running. If not - it will call '''systemctl start apache'''.
= Loops =
"filename"
Note that the "test -d" command will return true when applied to a directory and false otherwise.
 
== Resize images ==
 
This is the syntax for the convert command to resize an image original.jpg to a new image resized.jpg which is 1024 by 768 pixels large:
 
<source lang="bash">convert original.jpg -resize 1024x768 resized.jpg</source>
 
Write a script that will go through all the images in the current directory and make resized (1024x768) versions of each of them. Each existing image has a .jpg extension. New images should have a -small suffix. For example original.jpg should get a pair original-small.jpg
 
== Write HTML for images ==
 
In the images subdirectory of the current directory you have a pile of jpg images. You want to generate some code to put them all in a webpage. The HTML to show one image looks like this (the quotes around the filename can be single or double quotes):
 
<source lang="html4strict"><img src="images/imagefilename.jpg" /></source>
 
Write the script that will generate one big HTML file with an <img> tag for every image in the current directory.
 
== Write HTML for small images with links ==
 
This one is pretty advanced, but take it on if you want a challenge.
 
The same as above, but the current directory has two types of images: regular sized and small. Your generated HTML should look like this (again - either single or double quotes are fine for HTML):
 
<source lang="html4strict"><a href="imagefilename.jpg"><img src="imagefilename-small.jpg" /></a></source>

Navigation menu