Solved

Check Remote Folder Size from CMD line

Posted on 2006-10-31
17
8,349 Views
Last Modified: 2008-03-03
Hello

I simply want to check the folder size of a particular directory on a remote server i.e \\server1\dept

I am not concerned about the number of files or their size, just the size of the folder

I am looking for a way to do this from the cmd line since i need to check the sizes of 2 directories on about 70 servers

I have looked at the dir cmd switches but couldn't get it to show me the size of the directory

There are various utilities that can show me this info from within windows but it takes far too long.

I also looked at the DIRUSE reskit utility but it also took too long to return results.

Can someone help me out here

Thanks
0
Comment
Question by:master_windu
17 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17848247
Well apart from DIRUSE and TreeSize you could use a plain DIR command as follows.  It is always going to be slow as effectively it will run down all files in the dir no matter how you do it.

@echo off
set dirpath=\share\path\*.*
for /f "tokens=3" %%b in ('dir  /-c/s ^| find "File(s)"') do set total=%%b

You could run this against a server list with a batch file like this - ask if not sure on any of it.

@echo off
if not exist serverlist.txt echo servlist.txt not found & pause & goto end

for /f "tokens=*" %%a in (serverlist.txt) do call :process %%a

goto end
:process

for /f "tokens=3" %%b in ('dir  \\%1\%dirpath% /-c/s ^| find "File(s)"') do set total=%%b

:end

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17848261
Sorry you would probably want to add a line such as

echo %1, %dirpath%, %total%
echo %1, %dirpath%, %total% >> dirsize.txt

 before the :end line to write the output to a file and screen
0
 

Author Comment

by:master_windu
ID: 17849730

Thanks Dragon-it

Im not a big scripting person

I copied onto a text file and saved as dirsize.vbs

So if you could, can you show me how to modify the script you gave to give me the directory size for the following example:

\\server3\e$\dept
\\server3\e$\users

Also where do I need to save serverlist.txt?

thanks



0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17849876
Ah OK.  Tell you what then lets change it to put the server and path in the file:

serverlist.txt contains
server,path  
e.g.
server3,e$\dept

You can put servlist.txt wherever you like as long as you change the path.  I've made it easier by setting the path for it at the top of the file.  Same goes for the file with the results in.

hth

Steve

@echo off
set servlist=c:\serverlist.txt
if not exist %servlist% echo %servlist% not found & pause & goto end

set listfile=c:\dirsize.txt
del %listfile% 2>NUL

REM run down each entry in serverlist file and pickup servername and directory path and pass them to process sub
for /f "tokens=1,2*" %%a in (%servlist%) do call :process %%a %%b

goto end

REM for each path run a dir command run it through find to get the totals and pick up the last line into Total and echo it to a file
:process

for /f "tokens=3" %%x in ('dir  \\%1\%2 /-c/s ^| find "File(s)"') do set total=%%x

echo %1, %2, %total%
echo %1, %2, %total% >> %listfile%

:end
 
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17849896
This is batch file BTW.  It should be dirsize.cmd not VBS.

Steve
0
 

Author Comment

by:master_windu
ID: 17850972
Thanks

I tested it out on a local server and it worked.  However it would have been nice if there was an option to return the file size in MB

But when I ran it against a remote server it took way longer.  After about 5 mins i canceled it as no data had yet been returned.  If it takes that long to return folder sizes from remote servers then it wouldn't be a viable option for me since I need to check about 70 servers.  In the test the remote dirs each had about 5 gb of data

I looked at treesize but the free version does support network.  The pro version does but again it takes quite a long time to return results for just 1 remote dir

When I do a DIR \\serverX\e$\users I get a quick return but without the info I need.  Im looking for something more or less this fast that I can make a batch file out of to get me returns on all the servers.

0
 

Author Comment

by:master_windu
ID: 17851012
"But when I ran it against a remote server it took way longer.  After about 5 mins i canceled it as no data had yet been returned."

there were only 2 remote directories in the serverlist.txt file   fyi
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 17851417
I don't believe you will get anything fast though if you run it locally on the server it will be faster of course.  Any such program has to add up sizes of all files in the dirs.

if you left it going then a second run would probably be faster as the server caches the dir entries.

Even if you just use explorer and look at the properties of the dir you will notice it takes ages.

The command won't print anything until it has finished that dir.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17851645
btw type dir \\server\path /s/-c to see what it is doing.  It then pulls out the files(s) total lines using find.

Sorry it is no good but without some sort of indexer on the server it will always be a slow process.  Free space on the other hand is easy enough!

Could you not just set it to run last thing at night and leave it to give you a result the next morning :-)
0
 

Author Comment

by:master_windu
ID: 17853880
thanks for all your effort dragon-it

what i ended up doing was copying diruse.exe to the c$ dir of every file server via a batch file

then i created another batch file with psexec so that diruse runs locally on each server.

example

psexec \\server3 \\server3\c$\diruse /m \\server3\dept
psexec \\server3 \\server3\c$\diruse /m \\server3\users

this seems to work

ill output it to a text file
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17854225
fair enough.  You'd decided against diruse which is why I went down the route asked for but running it on the remote server with psexec or rclient /runbatch etc. is a much quicker idea if the option is avaialble to you.

If you write the output to a shared folder , I.e.>>\\server\share\servername.txt then it is easy enough to amalgamate into one with a copy command for instance. Or write it to same path on each server and pickup the logs afterwards with a for loop

Good luck

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18290553
I feel it more appropriate to select an answer I gave...I offered solutions and suggested the only way to make it run faster was to run it locally on the server - I did not elaborate on that as it had to be run remotely.
0
 
LVL 22

Expert Comment

by:WMIF
ID: 18447992
it seems to me that master_windu has come up with a solution to his problem which has not used your suggestions.  though you may have a more appropriate suggestion, this is not what master_windu used.  how can i recommend one of your answers in this case?

WMIF
EE Cleanup Volunteer
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18451406
OK, if he had said it could be run on the server I would have used the same scripts run on each box and amalgamted but lets just close the Q, not that bothered about it!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18715502
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now