[X-Unix] General Scripting Question

Brian Medley bpm-list-osx-unix at 4321.tv
Mon Apr 13 20:45:43 PDT 2009


This shows the free space on the / volume.

$ df -k | perl -ne 'next unless $_ =~ m#/$#; print;'                                                                 
/dev/disk0s2    116753840 105746456  10751384    91%    /

This shows if there is more than 5GB free.

$ df -k | perl -ne 'next unless $_ =~ \
m#/$#; print;' | perl -ane 'print("More than 5GB free\n") if \
$F[3] > 5_000_000;'
More than 5GB free

This will run a command if there is more than 5GB free.

$ df -k | perl -ne 'next unless $_ =~ m#/$#; print;' | perl -ane \
'exit(0) if $F[3] > 5_000_000; exit(1)' && echo "command here"
command here

On Mon, Apr 13, 2009 at 02:37:14PM -0500, Russell McGaha wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Folks;
> 	I want to look into something I'm not even sure is possible.
> 	Here's the scenario; I have a script that backs up a directory  
> [archives it] with the date in the name, this script runs every weekday.  
> What I want to do is; after making the archive, check the available space 
> on that drive, if it is under say 5GB, then check the free space on a 
> backup drive, and if the free space there is over say 10GB move the 
> oldest archives of the first drive onto the second.  When both drives are 
> too full, I want the script to send me an email letting me know I need to 
> clean the drives up.
> 	Anyone know if this is even possible??
>
>
> Russell
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.11 (Darwin)
>
> iEYEARECAAYFAknjlIEACgkQ5T2I5lFJnG+UJgCeMZjZTNGOHlWDVSs+4f2IQ8Kp
> 8r4AoNXphhho1UpsHz9VA7cPp1fl1D2t
> =zDFg
> -----END PGP SIGNATURE-----
> _______________________________________________
> X-Unix mailing list
> X-Unix at listserver.themacintoshguy.com
> http://listserver.themacintoshguy.com/mailman/listinfo/x-unix

-- 
Brian Medley


More information about the X-Unix mailing list