# Script df



## Lilly_S (Oct 10, 2011)

Basically I want to write a script which will run this [cmd=]df -k[/cmd]

I want it to do it automatically at a certain time and email the output. Can anyone help please?


----------



## DutchDaemon (Oct 10, 2011)

crontab(5)

Don't even need a script.


```
*/10 * * * *    /bin/df -k | /usr/bin/mail -s "df output" some.email.address 2>&1
```


----------



## Lilly_S (Oct 10, 2011)

*parsing a table*

Ok. I have changed my structure. I now have my output, however I want to parse it using perl or sed etc. I want to check each % and if it reaches a certain threshold to alert me.

Any idea how?


----------



## SirDice (Oct 10, 2011)

Lilly_S said:
			
		

> any idea how?


Yes, using perl or sed. Perl is probably easier if you also want to do something based on the info.


----------



## Lilly_S (Oct 10, 2011)

Ok, I will have a look at perl as I am new at this. If anyone has any idea how to do it please let me know.


----------



## Lilly_S (Oct 11, 2011)

*using perl*

i am stuck. can someone give me a pointer please in how to proceed?


----------



## mix_room (Oct 11, 2011)

0. Start perl 
1. Execute df and save the output
2. Parse the output 
3. Act on the parsed data. 

Easy as 1-2-3


----------



## jalla (Oct 11, 2011)

Here's a start 

```
df | perl -ne 'next if /^(Filesystem|devfs|procfs|linproc)/;if (/(\d+\%)\s+\S+/){$p=$1;} if( $p > 90){print;}'
```


----------

