LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 09-26-2017, 08:17 AM   #1
slayer_1994
Member
 
Registered: Feb 2017
Posts: 38

Rep: Reputation: Disabled
Script to watch disk space


Hi

I want to create a script looking at the % used for the disk space for 3 specific filesystems

I know the command df -h gives me the fileystems list etc but stuck on how I grep for the 3 filesystems

Code:
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      6.8G     0  6.8G   0% /dev
tmpfs                         6.8G     0  6.8G   0% /dev/shm
tmpfs                         6.8G  681M  6.1G  10% /run
tmpfs                         6.8G     0  6.8G   0% /sys/fs/cgroup
/dev/mapper/rootvg-rootlv      40G  3.8G   37G  10% /
/dev/sda1                     950M  307M  643M  33% /boot
/dev/mapper/rootvg-homelv     1.9G  195M  1.7G  11% /home
/dev/mapper/rootvg-tmplv      3.8G   33M  3.7G   1% /tmp
/dev/mapper/rootvg-itmlv      5.0G  508M  4.5G  10% /opt/IBM/ITM
/dev/mapper/vg101-lvol1        50G   22G   29G  44% /u101
/dev/mapper/vg01-lvol1        100G   23G   78G  23% /u01
/dev/mapper/rootvg-varlv      4.7G  1.4G  3.3G  31% /var
/dev/mapper/rootvg-calv        21G  531M   20G   3% /opt/ca
ccbtestnfs1:/CCBTEST_ARCHIVE   20G   32M   20G   1% /u50/CCBTEST_ARCHIVE
ccbtestnfs1:/CCBTEST          600G  295G  306G  50% /u50/CCBTEST
tmpfs                         1.4G     0  1.4G   0% /run/user/0
esdamlinux:/LINUX             331G  298G   19G  95% /LINUX
tmpfs                         1.4G     0  1.4G   0% /run/user/54348
tmpfs                         1.4G     0  1.4G   0% /run/user/120
tmpfs                         1.4G     0  1.4G   0% /run/user/74006
tmpfs                         1.4G     0  1.4G   0% /run/user/1905570915
I want to grep for the 3 following:

1. /opt/ca
2. u50
3. u01


Quote:
/dev/mapper/rootvg-calv 21G 531M 20G 3% /opt/ca
ccbtestnfs1:/CCBTEST_ARCHIVE 20G 32M 20G 1% /u50/CCBTEST_ARCHIVE
ccbtestnfs1:/CCBTEST 600G 295G 306G 50% /u50/CCBTEST
/dev/mapper/vg01-lvol1 100G 23G 78G 23% /u01
Thanks in advance
 
Old 09-26-2017, 08:59 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,885
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Hi,

So you have the commands and the additional qualifications for them (to pipe to grep)

I repeat something I've always said about bash scripts, which is
Quote:
Anything you can type into a command line, you can write into a bash script
Therefore, have you started a script? Do you know how to write a rudimentary bash script?

Please understand that LQ members are volunteers and we are happy to help you solve and/or refine a solution to your problem. But you need to execute that solution yourself, by writing a script and then asking members to help you if there are problems or to improve it somehow.

Please consider writing a script to do the command and then determine what additional things you want it to do. Note also that a single command is not necessarily helpful, and in fact you can more easily create an alias as opposed to writing a script. For a script, you likely would want to do other things. A script will work, but if your intent is to just make a shortcut for a command, then an alias may be better. Perhaps there are other things you intend to do or perhaps you intend to monitor this data regularly versus manually call it. Please update the forum with some additional information about this.

Best Regards.
 
Old 09-26-2017, 08:59 AM   #3
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,486

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
So what have you done so far?
 
Old 09-26-2017, 08:59 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,788

Rep: Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001
Quote:
Originally Posted by slayer_1994 View Post
Hi
I want to create a script looking at the % used for the disk space for 3 specific filesystems I know the command df -h gives me the fileystems list etc but stuck on how I grep for the 3 filesystems
Code:
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      6.8G     0  6.8G   0% /dev
tmpfs                         6.8G     0  6.8G   0% /dev/shm
tmpfs                         6.8G  681M  6.1G  10% /run
tmpfs                         6.8G     0  6.8G   0% /sys/fs/cgroup
/dev/mapper/rootvg-rootlv      40G  3.8G   37G  10% /
/dev/sda1                     950M  307M  643M  33% /boot
/dev/mapper/rootvg-homelv     1.9G  195M  1.7G  11% /home
/dev/mapper/rootvg-tmplv      3.8G   33M  3.7G   1% /tmp
/dev/mapper/rootvg-itmlv      5.0G  508M  4.5G  10% /opt/IBM/ITM
/dev/mapper/vg101-lvol1        50G   22G   29G  44% /u101
/dev/mapper/vg01-lvol1        100G   23G   78G  23% /u01
/dev/mapper/rootvg-varlv      4.7G  1.4G  3.3G  31% /var
/dev/mapper/rootvg-calv        21G  531M   20G   3% /opt/ca
ccbtestnfs1:/CCBTEST_ARCHIVE   20G   32M   20G   1% /u50/CCBTEST_ARCHIVE
ccbtestnfs1:/CCBTEST          600G  295G  306G  50% /u50/CCBTEST
tmpfs                         1.4G     0  1.4G   0% /run/user/0
esdamlinux:/LINUX             331G  298G   19G  95% /LINUX
tmpfs                         1.4G     0  1.4G   0% /run/user/54348
tmpfs                         1.4G     0  1.4G   0% /run/user/120
tmpfs                         1.4G     0  1.4G   0% /run/user/74006
tmpfs                         1.4G     0  1.4G   0% /run/user/1905570915
I want to grep for the 3 following:
1. /opt/ca
2. u50
3. u01
Glad to help; so what have you done/tried so far? Can you post your script and tell us where you're stuck? Read the "Question Guidelines" link in my posting signature.

I'd suggest storing whatever you want to look for in an array, and loop through the input to match those strings.
 
Old 09-26-2017, 09:37 AM   #5
slayer_1994
Member
 
Registered: Feb 2017
Posts: 38

Original Poster
Rep: Reputation: Disabled
Hi guys

I have created a script as shoown below:
Code:
df -H | grep -vE '^Filesystem|devtmpfs|tmpfs|esdamlinux|ccbtestnfs1' | awk '{ print $5 " " $1 }'
I know that what I have done above is filtering out the ones that I don't want but obviously this is quite a long winded approach, is there a quicker way?

Cheers
 
Old 09-26-2017, 10:12 AM   #6
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,486

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
1. u50 is technically two file systems
2. Failing to see why you're not just listing the points you're interested in:
Code:
df -h /opt/ca /u01 /u50/CCBTEST_ARCHIVE /u50/CCBTEST | awk {'print $5" "$1'}
 
1 members found this post helpful.
Old 09-26-2017, 11:52 AM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,838

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
Or grep for /dev/ at the beginning
Code:
df -kP | grep '^/dev/'
The df -kP output is better for post processing.
 
Old 09-28-2017, 03:09 AM   #8
slayer_1994
Member
 
Registered: Feb 2017
Posts: 38

Original Poster
Rep: Reputation: Disabled
Hi TenTenths

Great that is what I need. Thank you

Code:
[apm@ccbapprts1 ~]$ df -h /opt/ca | awk {'print $5" "$1'}
Use% Filesystem
3% /dev/mapper/rootvg-calv
Is there away to get rid of the output bringing the text Use% Filesystem

Cheers
 
Old 09-28-2017, 03:24 AM   #9
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,486

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Code:
| grep -v Filesystem
 
Old 09-28-2017, 03:33 AM   #10
slayer_1994
Member
 
Registered: Feb 2017
Posts: 38

Original Poster
Rep: Reputation: Disabled
Great stuff!

Thank you so much
 
  


Reply

Tags
diskspace, filesystem, grep, scripting, usage



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script for disk space alert cmontr Programming 6 02-09-2019 04:05 AM
LXer: How to monitor free disk space at Amazon EC2 with Cloud Watch LXer Syndicated Linux News 0 07-14-2015 08:43 AM
A script for looking at hard disk space wimnat Linux - Hardware 2 09-24-2009 09:09 PM
[SOLVED] Shell script to monitor or watch the disk space.... small help needed vikas027 Programming 5 10-21-2007 10:04 AM
script for checking disk space pralaydesai Linux - Networking 3 03-25-2003 03:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration