IT3110 @ utahtech
For this assignment you should create a script that receives three command-line arguments. The first argument is an IP address the second is a number (selection). The last one is the username that the script should ssh as. Your script MUST expect passwordless ssh to work. If you have to manually do anything during script execution, you need to fix it. Remember that do do passwordless ssh, you can use the ssh-copy-id
command to copy your keys to a remote machine. For example, if you are on the ssh server and want to login to scratch without a password, you can do ssh-copy-id d0000xxyy@scratch
The script does the following based on the number that they pass in:
one
.service ssh status
(replace ssh with whatever service that you are checking for)). You will have to do some grepping and awking to just get the actual status. I.e. I can grep this line Active: active (running) since Fri 2022-01-07 09:56:13 MST; 1 months 4 day>
to get the second word. So, the script will just print out that second word. This should be done in a function named two
./
filesystem on the remote machine. Hint: You can get the whole line for the /
by doing df | egrep '/$'
. You would then need to awk it to just give the percent field. This should be done in a function named three
.four
.five
.You should have a main
function that checks to see if any of the required input parameters are blank. If so, it should exit with a status of 1
(one). Otherwise, it determines what the selection
variable is set to and calls the appropriate function.
/dev/null
).ssh user@host "hostname"
ssh -o 'StrictHostKeyChecking no'
ssh user@host "some command | awk '{ print \$2 }'
. See the backslash in the awk statement.[[ "$0" == "${BASH_SOURCE[0]}" ]] && main "$@" || true
A good way to capture the output of the ssh command is as follows:
status=$(ssh -o 'StrictHostKeyChecking no' $user@$ip ${cmd})
echo $status
week2/assignment.sh
in your github repo.