Freespace report

Latest response

I am new to linux and have been trying to figure out how to get a report of free disk space on my RHEL servers. I can SSH into each one and run df-h to get the data I need, but I would like to script that so it runs as a cron job and then I just need to look at the output.

I have been trying to get a script to work where the IP address list is in a file called serverlist.txt. This is the latest on what I tried:



USER=< I would put the login here>

for host in cat serverlist.txt;
echo "Connecting to $host" >> freespace.txt
ssh $USER@$host "df -h" >> freespace.txt; "exit"


Serverlist has 3 IPs in it. When I run this script I only get the first IP in the output. The for loop does not seem to be moving down the list. How do I get this script to loop to the 3 IPs and run the command?

Again, please be easy on me :)


Hi Ryan,

The exit statement makes the script stop before trying the next iteration.

So remove it and run the script again.


Jan Gerrit

That worked! My confusion was the need to exit the SSH session on one server before I tried the next one.