COMP2101
Bash Assignment
The bash assignment consists of 3 parts. Each part will contribute to the total assignment mark. The rubric and submission for this assignment is on blackboard.
To get full marks for any script, your scripts must have the following elements as covered in class:
script interpreter line
command line processor using while, shift, and case if the script allows command line options or arguments
comments describing the script
error messages going to stderr
correct exit status
Add command line arguments to a script
The following script fragment will roll virtual dice and show what was rolled and what the total rolled was.
sum=0
while [ $count -gt 0 ]; do
roll=$(( $RANDOM % $sides +1 ))
sum=$(( $sum + $roll ))
echo "Rolled $roll"
count=$((count - 1))
done
echo "You rolled a total of $sum"
This script expects two variables to be defined before it runs.
count should contains the number of dice to roll
sides should contain the number of sides each die should have
Modify the script to allow the user to run the script without any command line arguments which will cause it to roll a pair of 6-sided dice.
Accept the following command line options:
-h or --help should display command line syntax and exit successfully
-c N or --count N should set the count of dice to roll to N, N must be a number from 1 to 9
-s N or --sides N should set the number of sides per die to N, N must be a number from 4 to 20
Display an error message and exit with a failed status if the user puts bad input on the command line.
Memory Usage Report
Create a simple but human friendly report on memory usage. You can use the free command to get the data for your report.
Display a report title
Display the total amount of RAM installed and the amount of free RAM
Calculate and display the sum of the used and cached RAM
Calculate and display the difference between the available and free amounts
Calculate and display how much RAM is shared as a percentage of the RAM used
Calculate and display how much RAM is used as a percentage of the total RAM
Calculate and display how much RAM is used for cache as a percentage of the total RAM
Your report should have a title. Each output data item should be appropriately labelled and scaled to display in megabytes. No command line options or arguments are required for this script.
Command Source Identification
Create a simple script that asks a user for command names, then tells them which software package the command comes from if it comes from a package that is installed on the system. You can use the dpkg -S filepath command to identify the software package.
If the user gives no command names as arguments on the command line, ask them for a command name, identify the source according to the rules below, and then ask for the next command name in a loop
If the user gives you one or more command names as arguments on the command line, identify sources for them instead of asking for file names
Accept a command line help option to display command help
Rules for identifying the source of a command name:
If the user just hits enter when asked for a command name, exit successfully
If the user gives a non-existent command name, give them an error message and move on to the next command name
If they give you a command name that didn’t come from a software package, tell them that it didn’t and tell them the full pathname of the file containing the command and who owns that file
If they give you a command name that doesn’t come from a file, tell them and move on to the next command name
Hi,
Looks like this is an assignment work. I can write a bash script for your requirement. But would like to know when you need. I cannot write in 5 or 10 hours as i already have some project ongoing. If you give me 24 hours, i can complete and give it for you.
You can review my profile and if interested please contact.
Thanks
Hello,
I have done this script earlier and can provide the answer now.
You can check the script and pay. I have also done the scripts "Add command line arguments to a script" and "Command Source Identification"
The script for `Memory Usage Report` is not done. I can do it in few hours.
Let me know if you are interested
hello,how are you. i read your bid carefully.
i am c/c++, linux expert and have full experience for 10 years.
c/c++, linux is my top skill and i can complete your project by using c/c++, linux.
i can provide most quality and high speed.
if you want to success, please contact me.
Then, I will give you good result to the proposals.
hire me.
I am a programmer who did a lot of programming for fun during my nerd years, before I actually came to college. During that time I read a lot about bash scripting, and I think I can easily do this task.
As proof of concept , i attach the first part of the task with the bid. Please let me know what you have studied in class so i can fine tune this. I have just started freelancing and I do not have any issue with accepting a low payment for my first project.
I will be available in the time period: 10 am to 12 pm, GMT +5.
#!/usr/bin/env bash
count=0
sides=0
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-c)
count="$2"
shift # past argument
shift # past value
;;
-s)
sides="$2"
shift # past argument
shift # past value
;;
esac
done
# echo $ $count
if !([ "$count" -ge 1 ] && [ "$count" -le 9 ]);then
echo "The variable count has an invalid value" > /dev/stderr
fi
if !([ "$sides" -ge 4 ] && [ "$sides" -le 20 ]);then
echo "The variable sides has an invalid value" > /dev/stderr
fi
sum=0
while [ "$count" -gt "0" ]; do
roll=$(( $RANDOM % $sides +1 ))
sum=$(( $sum + $roll ))
echo "Rolled $roll"
count=$((count - 1))
done
echo "You rolled a total of $sum"
This is a good opportunity to write an well documented script to meet your needs. It should not be rushed and it should be awarded to someone dedicated to quality and that knows how to deliver clean scripts. I am sure you will have less expensive bids but I am sure they will miss some of the requirements. I will not. I have been writing scripts for System Administration tasks of very large networks and I know how to deliver on time and with high quality.