#!/bin/bash function usage () { printf "Usage: %s \n" $( basename $0 ) } function check_args () { #remember $1 is the first arg sent to function #$2 is second (filename) if (( $1 < 0 || $1 > 100 )) then echo "Out of range"; usage; exit 1; fi echo $2 if [ ! -f "$2" ] then echo "Invalid file"; usage; exit 1; fi } #dont echo anything else out in this function function check_space () { threshold=$1 machine=$2 cmd="df -h | egrep '/$' | awk {' print \$5 '} | sed 's/%//'" #echo $cmd current_usage=$(ssh $machine "$cmd") #echo "curr: $current_usage, thresh: $threshold" if (( $current_usage > $threshold )) then echo True else echo False fi } threshold=$1 filename=$2 check_args $threshold $filename for machine in $(cat $filename) do #theoretically we would ssh to each of the machines to check if they are over threshold, but I did not. over_threshold=$(check_space "$threshold" "$machine") #check_space "$threshold" "$machine" if [ "$over_threshold" == "True" ] then echo "We need to clean things up" #run_updates # I didn't write this function. It would essentially just do apt update and autoclean else echo "you are below the threshold, good job" fi done