Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to update a hard drive's free space value' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to update a hard drive's free space value
Authored by: Cerberus on Sep 01, '05 10:09:04PM

Use this script to place the space.txt file on every local drive and then (per rob's excelent suggestion) remove it.

#!/bin/sh
HD_ROOT_PATH=$(df -l | grep -i dev | awk ' { print $6}')
#echo -e "Root Path = "$HD_ROOT_PATH
for i in $HD_ROOT_PATH
do
if [ -d $1 ] ; then
#echo -e "Found a dir @ "$i
cp /Users/Shared/space.txt $i
rm $i/space.txt
fi
done


As you may be able to see I put the space.txt file in /Users/Shared. I think this is a better place for it as then this script does not rely on any personal accounts to copy a file in (just in case your account goes wonky etc.)

P.S. I left in some echo's so you all can 'watch' what it is doing if you so desire.



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: Cerberus on Sep 02, '05 11:29:21AM

OK I just found out that this script works on any locally mounted device that does not cotnain a space in the name. Anyone have a suggestion for fixing this? This is the only limitation that this sctipt has now...



[ Reply to This | # ]
A script to update a hard drive's free space value
Authored by: Cerberus on Sep 02, '05 11:41:23AM
here is the final code (works much better now) should work under every circumstance:

#!/bin/sh
HD_ROOT_PATH=$(df -l | grep dev | cut -b 54-)
#echo -e "Root Path = "$HD_ROOT_PATH
for i in $HD_ROOT_PATH
do
 if [ -d "$i" ] ; then
  #echo -e "Found a dir @ $i"
   cp /Users/Shared/space.txt "$i"
   rm "$i"/space.txt
 fi
done


[ Reply to This | # ]