Sponsored Content
Top Forums Shell Programming and Scripting Monitor capacity of directory Post 302321501 by LRoberts on Monday 1st of June 2009 10:44:57 AM
Old 06-01-2009
Question Monitor capacity of directory

Good morning.

I have been attempting to find a way to monitor the capacity of a directory so that when it reaches 80% or higher I can send an event.

I was able to find a script that does this for the whole drive by I can not seem to figure out how to do this for just a single directory.

Code:
ADMIN="myemail@someplacecool.com"
# set alert level 90% is default
ALERT=60
df -hl | egrep -ve '/lcl/prd/apps/Tivoli/playground' | awk '{ print $5 " " $1 }' | while read output;
do
  echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done

As you can see from above I am attempting to get the capacity of /lcl/prd/apps/Tivoli/playground and if its 90% or over then it sends an e-mail.

However when I try this is the results...
Code:
"test.sh" 14 lines, 586 characters
seville:/lcl/prd/apps/Tivoli/playground>./test.sh
capacity Filesystem
./test.sh: line 10: [: capacity: integer expression expected
81% /dev/md/dsk/d10
0% /devices
0% ctfs
0% proc
0% mnttab
1% swap
0% objfs
0% sharefs
0% fd
1% swap
1% swap
67% /dev/md/dsk/d100

I am not very good yet with shell scripting so I am kinda stuck here.
Any help would be great.

Thank you.

-----Post Update-----

Figured it out.

Code:
#!/bin/ksh
space=`df -bhk /lcl/prd/apps/Tivoli/playground | cut -d "c" -f1 | awk '{print$5}'`
capacity=${space%?}
echo $capacity
if [ $capacity -gt 70 ]; then
echo "Getting full! $capacity"
else
echo "Below percent trap."
fi

 

10 More Discussions You Might Find Interesting

1. Programming

Monitor which users enter my home directory

Hi, I would like to monitor which users enter my home directory. Is it possible to write a script or code to do this. I donot have admin privileges. I have given read permissions to access my home directory. Any pointers in this direction is helpful! Thanks, Pradeep Ps: I use the... (1 Reply)
Discussion started by: mnpradeep
1 Replies

2. UNIX for Dummies Questions & Answers

Hep with script to monitor directory

Hello, I am a newbie who is attempting to write a script to monitor a directory for a set of 3 files that I am expecting to get ftp'd. Occasionally, we suspend operations for maintenance etc. but we still get the files so there can be more than 1 set. If there is more than 1 set, I would like... (2 Replies)
Discussion started by: cmf00186
2 Replies

3. Shell Programming and Scripting

script to monitor directory

What is the best way for a script to run to monitor a directory for the presence of files and then perform a function afterwords? I was hoping to have it continually run and sleep until it detects that files are present in the directory, then break out of the loop and go on to the next step. ... (17 Replies)
Discussion started by: nulinux
17 Replies

4. Shell Programming and Scripting

Capacity of directory... Pulling hair out :-)

I am new to scripting and thought I was doing rather well however I ran into a issue and I am not sure how to fix it. I am using the following command to obtain the capacity percent of the directory listed however it seems that this command gets the capacity of the whole mount rather then just the... (8 Replies)
Discussion started by: LRoberts
8 Replies

5. AIX

monitor directory events

I'm am looking for a cheap way to trigger a script when a new file is written in a specific directory. AIX 5.3. It is a production system, so no kernel patching (i.e. inotify). Filemon and audtiing are too expensive. Thanks in advance. (2 Replies)
Discussion started by: pbillast
2 Replies

6. UNIX for Dummies Questions & Answers

Monitor directory and email

Hello all, Can anyone please guide / help me in the following task.... I have a directory where some external users will upload pdf files. The filename of these pdf will be of a particular format (<id>-<first name>_<last name>_<some number>.pdf) I want to make a script such that it takes... (6 Replies)
Discussion started by: dhawalkv
6 Replies

7. Shell Programming and Scripting

Directory Monitor in KSh

Hi, I need to write a directory monitor, i.e. a korn shell script which would Report changes to the directory contents, like: added file1, deleted file2, updated file3 , created subdir (optional)... There is no specific file pattern. So far I have written a little script... (1 Reply)
Discussion started by: olegkon
1 Replies

8. Shell Programming and Scripting

howto monitor a directory for files then sftp them

Morning all I hope I have put this in the correct forum. I have a requirement to monitor a directory on a server for files being sftp'ed in and then to sftp them of to another server. The issues I have though of are making sure the files have completely transferred onto the server before they... (6 Replies)
Discussion started by: ltodd2
6 Replies

9. Shell Programming and Scripting

monitor(audit) and log changes inside directory

Hi, everyone I would like to write ksh script in ksh (HP-UX), to audit any changes inside target directories. My enviroment has many constrains, so I can only use ksh and cannot install any 3rd party soft or command (include perl or other languages) The script functions like below 1) take a... (1 Reply)
Discussion started by: stev.h
1 Replies

10. Shell Programming and Scripting

awk to monitor size in directory

i'm trying to find the most efficient way to monitor specific files in different directories in one go. /var/log/ /var/app/ /var/db/ each one of these directories can have subdirectories which need to be looked into as well. I want to find any file in this directory that has the name... (7 Replies)
Discussion started by: SkySmart
7 Replies
ACPIBAT(4)						   BSD Kernel Interfaces Manual 						ACPIBAT(4)

NAME
acpibat -- ACPI Battery SYNOPSIS
acpibat* at acpi? DESCRIPTION
The acpibat driver supports ACPI batteries. The battery status is made available through the envsys(4) API. The battery information can be displayed also with the envstat(8) command: $ envstat -d acpibat0 Current CritMax WarnMax WarnMin CritMin Unit present: ON design voltage: 14.400 V voltage: 16.267 V design cap: 74.880 Wh last full cap: 48.260 Wh charge: 47.910 5.000% 0.414% Wh (99.27%) charge rate: N/A discharge rate: 16.641 W charging: OFF charge state: NORMAL Depending on the battery, the unit of measurement is either watt-hour (Wh) or ampere-hour (Ah) for the capacity related information. From these the ``charge'' is usually the most interesting value, but it is possible to derive useful information also from the other values. For example, when acpiacad(4) is disconnected, the ``discharge rate'' gives a coarse approximation of the current power consumption. The ratio between the design capacity and the last full capacity on the other hand reveals the overall ``health'' of deteriorating lithium-ion batter- ies. EVENTS
The acpibat driver is able to send events to powerd(8) daemon when a capacity state has been changed. The new state will be reported as the fourth argument to the /etc/powerd/scripts/sensor_battery script. If a custom capacity limit was set via envstat(8), the acpibat driver will report a user-capacity event to the same script when current capacity limit has been reached. SEE ALSO
acpi(4), envsys(4), envstat(8), powerd(8) HISTORY
The acpibat driver appeared in NetBSD 1.6. BUGS
The ACPI specifications make a distinction between ``control method batteries'' and ``smart batteries''. The acpibat driver only supports control method batteries. Furthermore, acpibat does not yet support some additional battery information introduced in the ACPI 4.0 standard. BSD
March 17, 2010 BSD
All times are GMT -4. The time now is 02:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy