How do I display amount of free space on Hard Drive

How do I display amount of free space on Hard Drive

Post by Fusa » Thu, 08 Jul 2004 20:20:39


I want to write a script for eggdrop that will show the amount of free
space on a hard drive.
 
 
 

How do I display amount of free space on Hard Drive

Post by David Coba » Thu, 08 Jul 2004 20:35:45

Fusa < XXXX@XXXXX.COM > a rit :

something like this on unices :

exec df -h | tr -s "\t" " " | cut -d " " -f 1,4 | grep /

--
cordialement
david cobac

 
 
 

How do I display amount of free space on Hard Drive

Post by Fusa » Thu, 08 Jul 2004 21:11:28

David Cobac < XXXX@XXXXX.COM > wrote in



I am using Windows XP
 
 
 

How do I display amount of free space on Hard Drive

Post by Arjen Mark » Thu, 08 Jul 2004 21:41:25


Well, in line with David's reply but for Windows XP:

set info [eval exec [auto_execok dir]]
set freespace [lindex [lindex [split $info \n] end] 2]

Regards,

Arjen
 
 
 

How do I display amount of free space on Hard Drive

Post by clair » Thu, 08 Jul 2004 22:06:58

In article < XXXX@XXXXX.COM >,

.
.
.
Related material appears at <URL: http://www.yqcomputer.com/ ; and
under "Disk free capacity" within <URL: http://www.yqcomputer.com/ ;.
 
 
 

How do I display amount of free space on Hard Drive

Post by Fusa » Fri, 09 Jul 2004 07:08:29

Arjen Markus < XXXX@XXXXX.COM > wrote in




free

I have tried adding this to my script:

set free [expr [lindex [lindex [split [exec cmd /c dir /-c z:] \n] end]
0]/1024]
puthelp "PRIVMSG $chan :Free space $free"

Although, I receive the error:

Tcl error [pub:new]: couldn't duplicate input handle: bad file number

I want this script to display the free space on drive z:
 
 
 

How do I display amount of free space on Hard Drive

Post by Fusa » Fri, 09 Jul 2004 09:01:35

Fusa < XXXX@XXXXX.COM > wrote in





end]

Ok, it is working so far, I used..

set info [exec cmd /c dir z:]
set free [lindex [lindex [split $info \n] end] 2]
puthelp "PRIVMSG $chan :7,1...$free bytes Free For Uploads..."


Which returns...

...17,061,990,400 bytes Free For Uploads...

How do I convert this to megabytes? I had to take out the expr for it to
work, and added -nt to eggdrop when I started the bot
 
 
 

How do I display amount of free space on Hard Drive

Post by Fusa » Fri, 09 Jul 2004 09:15:35

Fusa < XXXX@XXXXX.COM > wrote in





end]

Ok, its working fine now, with

set info [exec cmd /c dir /-c z:]
set free [lindex [lindex [split $info \n] end] 2]
set freemb [ expr $free / 1048576 ]
puthelp "PRIVMSG $chan :7,1...$freemb MBs Free..."


Thanks to everyone for all the help!!!

I'm slowly learning this language.
 
 
 

How do I display amount of free space on Hard Drive

Post by Arjen Mark » Fri, 09 Jul 2004 16:01:34


Hm, the error you got does not seem related to the code.
Essentially, the last posting just splits up the various
commands.

My guess is that the z-drive had a slight hickup. That
may be soemthing to watch out for.

Try:

for { set i 0 } { $i < 3 } { incr i } {
set error [catch {
set info [exec cmd /c dir /-c z:]
set free [lindex [lindex [split $info \n] end] 2]
set freemb [ expr $free / 1048576 ]
}] msg

if { $error == 0 } {
break
}
}

if { $error != 0 } {
puts "Failed to get the free disk space after 3 tries:\n$msg"
}

This will try at most 3 times to get the free disk space, and
print an error message if that did not work. You may want
to put in an "after 100" or something to wait 100 ms.

Regards,

Arjen
 
 
 

How do I display amount of free space on Hard Drive

Post by Donal K. F » Fri, 09 Jul 2004 17:35:41


To convert, remove the comma characters and divide by the size of a
megabyte. It's probably a good idea to then trim off fractional pieces
neatly too. :^)

# Set this once...
set FREESPACEMSG "PRIVMSG %s :7,1...%.2fMB Free For Uploads..."

set info [exec cmd /c dir z:]
set freeBytes [lindex [split $info \n] end 2]
set freeMB [expr {[string map {, {}} $freeBytes] / 1048576.0}]
puthelp [format $FREESPACEMSG $chan $freeMB]

Note that you'll need Tcl 8.4 or later to make that work as written
given the size of that disk. If you haven't got that, replace the line
calculating freeMB with these:

# Replace [string map] with version that works in Tcl8.0
regsub -all , $freeBytes {} tmp
# Force floating point interpretation of the >32bit value
set freeMB [expr {"$tmp.0" / 1048576}]

Note that some people (especially disk manufacturers for some reason)
seem to feel that a MB should refer to one million bytes, and not to
2**20 bytes...

Donal.
 
 
 

How do I display amount of free space on Hard Drive

Post by lvirde » Fri, 09 Jul 2004 22:29:33


According to Cameron Laird < XXXX@XXXXX.COM >:
:In article < XXXX@XXXXX.COM >,

:>Fusa < XXXX@XXXXX.COM > a rit :
:>>I want to write a script [...] that will show the amount of free
:>>space on a hard drive.

:Related material appears at <URL: http://www.yqcomputer.com/ ; and
:under "Disk free capacity" within <URL: http://www.yqcomputer.com/ ;.


I am surprised that something like this hasn't made it into
Tcllib [ http://www.yqcomputer.com/ ] ; it seems like a natural

Arjen, any chance that you could take the code you wrote, and perhaps
something from the wiki, and turn it into something for the fileutil
module?

--
<URL: http://www.yqcomputer.com/ ; In God we trust.
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto: XXXX@XXXXX.COM > <URL: http://www.yqcomputer.com/ ;
 
 
 

How do I display amount of free space on Hard Drive

Post by Darren Ne » Fri, 09 Jul 2004 23:22:10


The reason being that disks aren't addressed in powers of two. (Plus, of
course, it makes the disk sound bigger.)

Note that the same is true of telephony measurements, such as "kilobits
per second."
 
 
 

How do I display amount of free space on Hard Drive

Post by donal.k.fe » Sat, 10 Jul 2004 06:03:47


Err, but disks are addressed in powers of two. Specifically in units
of 512 bytes, though many OSes work with multiples of that.


(Sssh! That's just the real reason! Don't let on!)

Donal.
 
 
 

How do I display amount of free space on Hard Drive

Post by Fusa » Sat, 10 Jul 2004 07:12:52


@wldelft.nl:


number

For exec to work with windrop it has to be started with the -nt switch,
as far as I know, once I added that the script worked ok (the reason for
splitting it up was just me learning the commands)
 
 
 

How do I display amount of free space on Hard Drive

Post by Fusa » Sat, 10 Jul 2004 07:15:23

"Donal K. Fellows" < XXXX@XXXXX.COM > wrote in




I just used
exec cmd /c dir /-c z:

(added the /-c switch to dir)
This worked fine, it was recommended before, but when I was trying to
figure out what was causing exec to fail I took it out (the problem ended
up being having to start windrop with -nt switch for exec to work)