Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi! I'm trying to write a script that prints the % of disk space if it's under %80:
Example:
/var/log %50 # it prints
/opt %81 # doesn't print
Script results:
/var/log %50
I'm using the df -Ph command but can't find out how to print it if it's under %80. df's printing everything. Any ideas? Googling's not helping. Thanks!
Hi! I'm trying to write a script that prints the % of disk space if it's under %80:
Example:
/var/log %50 # it prints
/opt %81 # doesn't print
Script results:
/var/log %50
I'm using the df -Ph command but can't find out how to print it if it's under %80. df's printing everything. Any ideas? Googling's not helping. Thanks!
Quote:
Originally Posted by Tonybe
Doh! Sorry!
Code:
#!/bin/bash
SERVER_LIST=$1
if [ -z "$1" ]; then
echo -e "\nNo arguments supplied!\n"
echo -e "\nPlease call '$0 <argument>' to run this command!\n"
exit 1
fi
echo " "
for HOST in `cat $SERVER_LIST`
do
echo "Servername : $HOST"
echo -e "Disk Space for /opt: "; rosh -l root -n $HOST -t "df /opt/"
echo "------------------------------"
done
echo " "
Please use [code] tags when posting code or output. See the link in my signature.
The code in the script doesn't match what you said in the OP, so we're still not clear on what you're doing.
df won't filter by size, you'd need to apply additional filters to the output of the df command. I'd suggest grep or awk.
As you say, df prints everything, so first you'd need to filter out (exclude) the lines that are not "real", those with Filesystem tmpfs (df -x), or include those that are (df -t) See man df
Then, you'd need to use grep or awk to select the lines you want to see, based on the Use% column. See their man pages.
I am curious why you want to only see partitions where the Use% is below 80%...I'd think the ones that are fuller -- higher than 80%, would be of more concern.
And nothing speaks against the -P option that was initially suggested.
Certain versions of df break a long in two even if the output device is not a terminal - the -P prevents that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.