LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-20-2003, 02:08 PM   #16
PTBmilo
Member
 
Registered: Jan 2003
Posts: 167

Rep: Reputation: 30

It looks like it's messing up here:
Code:
for i in $( fdisk -l | cut -c1-9 | grep /dev/ )
Did you put a 'l' (as in Lamda) for the argument after fdisk?

If that's not it, post the output of:
bash$ fdisk -l | cut -c1-9 | grep /dev/

I'm thinking that this method might not be very portable....

p.s.- Note my reply to acid_kewpie.... it turns out that 'paste' wanted a file... but we don't need paste if we put it all in an echo containing `date`.

Last edited by PTBmilo; 02-20-2003 at 02:26 PM.
 
Old 02-20-2003, 02:46 PM   #17
cuss
Member
 
Registered: Dec 2002
Posts: 63

Original Poster
Rep: Reputation: 15
Here is the output from the command you suggested:

-------------------------------------------------------------------------
[root@xxxx]# bash$ /sbin/fdisk -l | cut -c1-9 | grep /dev/
bash: bash$: command not found
--------------------------------------------------------------------------

Note that I get the same output from the server that your script works on.

Also, what works for me is '/sbin/fdisk -l'on my one server (that is where fdisk is located (redhat 7.2). In your script you have 'fdisk -l'.

With the changes from yourelf and acid_kewpie would this be the final script (in my case):

-----------------------------------------------------------------------------------
#!/bin/bash
for i in $( /sbin/fdisk -l | cut -c1-9 | grep /dev/ ) # Get all partitions
do
if [ "$( df -h $i | grep -v U | cut -c40-42 )" -ge "80" ]; then

date > /tmp/date_output.txt

echo "`df -h $i | cut -c1-10,40-43 | grep /dev` `date`" \
>> /var/log/disk_free.log
fi
done
------------------------------------------------------------------------------------

Thanks.
 
Old 02-20-2003, 02:58 PM   #18
PTBmilo
Member
 
Registered: Jan 2003
Posts: 167

Rep: Reputation: 30
Congrats... I'm glad it works.

p.s.- I didn't mean for you to put the "bash$" in there

Also, you don't need the 'date > /tmp/date_output.txt' line in there anymore (it's not used because of the alterations mentioned.)

edit:
If you want to see what is going on in here, single out the commands. Start with the first, then add a pipe, then the next, and so on. ex (I'm not showing the output):
Code:
[/home/milo]> /sbin/fdisk -l
[/home/milo]> /sbin/fdisk -l | cut -c1-9
[/home/milo]> /sbin/fdisk -l | cut -c1-9 | grep /dev/

Last edited by PTBmilo; 02-20-2003 at 03:09 PM.
 
Old 02-20-2003, 03:45 PM   #19
cuss
Member
 
Registered: Dec 2002
Posts: 63

Original Poster
Rep: Reputation: 15
Oops my bad. The script works on the server where all partitions are /dev/hda. On the server with 5 /dev/hdc partitions and 1 /dev/sda partition this is the output i get when i run your command.

------------------------------------------------------------------------------------
[root@xxxx]# /sbin/fdisk -l

Usage: fdisk [-l] [-b SSZ] [-u] device
E.g.: fdisk /dev/hda (for the first IDE disk)
or: fdisk /dev/sdc (for the third SCSI disk)
or: fdisk /dev/eda (for the first PS/2 ESDI drive)
or: fdisk /dev/rd/c0d0 or: fdisk /dev/ida/c0d0 (for RAID devices)
...
------------------------------------------------------------------------------------

And this would be the good copy of the script:

-----------------------------------------------------------------------------------
#!/bin/bash
for i in $( /sbin/fdisk -l | cut -c1-9 | grep /dev/ ) # Get all partitions
do

if [ "$( df -h $i | grep -v U | cut -c40-42 )" -ge "80" ]; then

echo "`df -h $i | cut -c1-10,40-43 | grep /dev` `date`" \
>> /var/log/disk_free.log

fi

done
------------------------------------------------------------------------------------


Thanks!
 
Old 02-20-2003, 04:04 PM   #20
PTBmilo
Member
 
Registered: Jan 2003
Posts: 167

Rep: Reputation: 30
What does this give you (on the server that the script doesn't work on)?

(first one will give the fdisk version)
Code:
[/home/milo]> fdisk -v
[/home/milo]> fdisk /dev/[hs]d? -l
What distro is it on?
 
Old 02-21-2003, 10:01 AM   #21
cuss
Member
 
Registered: Dec 2002
Posts: 63

Original Poster
Rep: Reputation: 15
I try both of the above commands. Here is the output:

[root@xxxxx /root]# /sbin/fdisk -v
fdisk v2.9w

[root@xxxxx /root]# /sbin/fdisk /dev/[hs]d? -l
Device Boot Start End Blocks Id System
#All information for /dev/hdc and /dev/sda is listed here

It is on a redhat system, kernel 2.2.12-20. I believe redhat version 6.1.
 
Old 02-21-2003, 10:39 AM   #22
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
yeah some versions of fdisk insist on being told which device to list, some default to all.... not sure if it's newer or older versions that do this...
 
Old 02-21-2003, 10:42 AM   #23
PTBmilo
Member
 
Registered: Jan 2003
Posts: 167

Rep: Reputation: 30
Cool, if that lists everything, then I thin you can stick that into the program.
Code:
for i in $( /sbin/fdisk /dev/[hs]d? -l | cut -c1-9 | grep /dev/ )
If something screws up, then post exactly what the output of just the fdisk command is.

By the way, the [hs] means it will match everything that starts with an h or an s, and the ? will match any single character.
 
Old 02-21-2003, 03:28 PM   #24
cuss
Member
 
Registered: Dec 2002
Posts: 63

Original Poster
Rep: Reputation: 15
Well, I've got the script on 3 servers now and all produce output to /var/log/disk_free.log every 60 minutes which is great. The problem now is that i setup cron to email me if disk space is over a certain percentage once it starts the script every 60 minutes. However the emails aren't getting to me (one of the servers is over its threshold so i should get something). Don't know if you know much about cron. But thanks for the help on the disk space script!!! Here is my crontab entry:

------------------------------------------------------------------------------
#check disk space every 60 minutes
MAILTO=me@mycompany.com
00 * * * * /usr/local/bin/disk_space.sh
------------------------------------------------------------------------------

I was receving the emails yesterday telling me i had my syntax for the /sbin/fdisk line incomplete. Any suggestions?

Thanks.
 
Old 02-24-2003, 05:32 PM   #25
PTBmilo
Member
 
Registered: Jan 2003
Posts: 167

Rep: Reputation: 30
You can use the script to notify you. I don't really know the format that you want in the e-mails, but here's an example to work from:

below the ">> var/log/disk_free.log" line in the script:
Code:
tail /var/log/disk_free.log | mail -s "DISK USAGE ALERT ON `hostname -f`" your@address
The only thing about this is that it will send you 1 email for every single partition that is over 80% used (every hour). Maybe if I get some time I'll post a better solution.

EDIT:
What do you mean you were getting e-mails saying that the fdisk command was incomplete? What did they say? I can try to help if you tell me what is going wrong.

Last edited by PTBmilo; 02-24-2003 at 05:34 PM.
 
Old 02-24-2003, 07:15 PM   #26
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally posted by PTBmilo

The only thing about this is that it will send you 1 email for every single partition that is over 80% used (every hour). Maybe if I get some time I'll post a better solution.
In cases like that, I use something like:
Code:
#!/bin/bash

REPORT=/tmp/df_report_$$.txt
THRESH=80
TRUE="1 eq 1"
FALSE="1 eq 0"

WROTETOREPORT=$FALSE

df -k | grep -v "Mounted on" | while read DFREC
do
    SPECIAL=`echo $DFREC | awk '{ print $1 }'`
    FS=`echo $DFREC | awk '{ print $6 }'`
    USE=`echo $DFREC | awk '{ print $5 }'`
    PERCENT=`echo $USE | sed 's/%//'`
    if [ $PERCENT -gt $THRESH ]
    then
        WROTETOREPORT=$TRUE
        echo "$SPECIAL ($FS) is at $PERCENT percent." >> $REPORT
    fi
done
if [ $WROTETOREPORT ]
then
    cat $REPORT | mutt -s "Filesystems above $THRESH percent on date +'%Y-%m-%d %H:%M'" root@localhost
    rm -f $REPORT
fi
Or something like that. It looks wierd at first but I use the variables (which are normally sourced, loaded as a module, or included as a header) to hold the boolean values so I don't have to remember what's true/false in shell, what's true/false in perl, etc.
 
Old 02-25-2003, 12:44 PM   #27
cuss
Member
 
Registered: Dec 2002
Posts: 63

Original Poster
Rep: Reputation: 15
Hi PTPmilo,

Thanks again for all of your responses and most recently your one line solution to my emailing problem.....it's no longer a problem. All 3 servers are doing what they should be now.

----------------------------------------------------------------------------------
EDIT:
What do you mean you were getting e-mails saying that the fdisk command was incomplete? What did they say? I can try to help if you tell me what is going wrong.
-----------------------------------------------------------------------------------
No longer an issue.....thanks anyways.

Thanks to you to rnturn for the script you provided and everyone else for their help along the way. Hopefully this issue is now a closed case (at least by me).

Cheers.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
hard disk monitoring tool malo_umoran Slackware 3 08-14-2005 01:05 PM
out of disk space... snoply Linux - Enterprise 6 05-06-2005 08:56 AM
3Gb of disk space lost! Disk space problem or mother board conflicts with HDD Mistreated Linux - Hardware 4 12-06-2004 03:58 PM
Monitoring disk space on webserver!!! apache Linux - Software 2 07-27-2004 07:47 AM
Disk space wastage 73 GB Hard disk rajgopalhg Linux - Hardware 2 10-18-2002 03:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:55 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