LinuxQuestions.org
Register a domain and help support LQ
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 07-21-2010, 11:50 PM   #1
kma07
LQ Newbie
 
Registered: May 2010
Posts: 6

Rep: Reputation: 0
Question df script not working


Hi guys, I have a script that checks disk usage and emails if it is low but it keeps returning this error:


Use of uninitialized value in concatenation (.) or string at ./df.pl line 17.
tail: cannot open `+2' for reading: No such file or directory
Use of uninitialized value in addition (+) at ./df.pl line 20.
Use of uninitialized value in addition (+) at ./df.pl line 20.
Use of uninitialized value in division (/) at ./df.pl line 20.
Illegal division by zero at ./df.pl line 20.


Here's the script:

Code:
#!/usr/bin/perl
use strict;
use warnings;

# file system to monitor
my $target = shift;

# warning level
my $warning_level=10;

# email setup
my $to='myemail@email.com';
my $from='email@myemail.com.au';
my $subject='Low Disk Space Warning';

# get df
my ($fs_dev, $fs_type, $size, $used, $avail, $use, $mount) = split(" ", `df -PT $target | tail +2`);

# calculate
my $df_free = (($avail) / ($avail+$used)) * 100.0;

# compare
if ($df_free < $warning_level) {
my $out = sprintf("WARNING Low Disk Space on $target : %0.2f%% ()\n",$df_free);

# send email using UNIX/Linux sendmail
open(MAIL, "|/usr/sbin/sendmail -t");

## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n";

## Mail Body
print MAIL $out;

close(MAIL);
}

Any ideas?
 
Old 07-22-2010, 12:59 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Well, we can start with this for one thing:

"tail: cannot open `+2' for reading: No such file or directory"

Code:
man tail
...
-n, --lines=K    output  the  last  K  lines, instead of the last 10; or use -n +K to output lines starting with the Kth
...
So it's "tail -n +2", not "tail +2".
 
Old 07-22-2010, 01:07 AM   #3
kma07
LQ Newbie
 
Registered: May 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Thumbs up Works now!

Works now!

Thanks

Last edited by kma07; 07-22-2010 at 01:17 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Crontab is not working, the script is working arfal SUSE / openSUSE 6 02-08-2010 09:48 PM
my first shell script isn't working extendedping Programming 3 02-26-2007 03:23 PM
SH Script not working PEACEYALL Linux - General 3 03-21-2005 09:58 AM
Help get this script working please rickenbacherus Linux - General 2 03-24-2004 07:25 PM
why my shell script is not working linuxlah Linux - General 4 08-01-2002 09:39 AM


All times are GMT -5. The time now is 10:02 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration