We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Any Command Prompt / Batch Gurus?

I'm trying to automate the enumeration of shares on a network.

I've got a list of all host names, and using a batch file, I have created a txt file for each host containing the NET VIEW output.

Each file has something similar to:
Share name                 Type  Used as  Comment

-------------------------------------------------------------------------------
[COLOR=Navy]ShareName1[/COLOR]                 Disk
[COLOR=Navy]ShareName2[/COLOR]                 Disk
[COLOR=Navy]Share Name 3[/COLOR]               Disk
[COLOR=Navy]Very Long Share Name[/COLOR]       Disk
The command completed successfully.

Is there a way via the command prompt to strip the files of all but the share names (in blue)?

I was thinking of using FOR "tokens=1 delims= " in a batch file, but then I thought some of the shares contain a space in them.

Does anyone know if I can change delims= to have 2 spaces after it?

Or is there better way?

Cheers
«1

Comments

  • rmg1
    rmg1 Posts: 3,159 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    No need if you have access to Excel.
    You can just read the text files into a separate worksheet for each one and then do the necessaries in there, either with VBA or some fairly simple formulae.
    If they are in a standard format, then you can use tab delimited format when reading them on to get them into separate cells and then do whatever else you need to do afterwards.
    :wall: Flagellation, necrophilia and bestiality - Am I flogging a dead horse? :wall:

    Any posts are my opinion and only that. Please read at your own risk.
  • John_Gray
    John_Gray Posts: 5,845 Forumite
    Part of the Furniture 1,000 Posts Name Dropper Photogenic
    Quite straightforward, provided that your environment always generates the output you post (mine certainly doesn't!). Create a BATch file containing

    @echo off
    setlocal
    for /f "tokens=*" %%a in (' net view ^| find "Disk" ') do call :process "%%a"
    :: I had to test this using the following line,
    :: because I don't get the results you do from NET VIEW
    ::for /f "tokens=*" %%a in (' type mse.txt ^| find "Disk" ') do call :process "%%a"
    endlocal
    goto :eof
    ::

    :process
    :: whole string gets passed to this subroutine
    set line=%1
    :: remove the double-quotes
    set line=%line:"=%
    :: strip off the last five characters (the "Disk" text)
    set line=%line:~0,-5%
    :: dunno what you want to DO with the sharename here, so I've just echoed it
    ECHO %LINE%
    goto :eof

    For each silly face replace it by : p (but without the space between the : and the p, of course!).

    See how it goes!
  • John_Gray
    John_Gray Posts: 5,845 Forumite
    Part of the Furniture 1,000 Posts Name Dropper Photogenic
    edited 4 June 2009 at 5:51PM
    I've just reread your post, and it seems my test method was closer to your reality.

    Post the names of the TXT files containing the share names you want to process (for example, is it *.txt in a directory?), and what output you want (names in a single file with the name of the host (presumably coming from Host1.txt, Host2.txt, and so on?), or one file per host name, or what)?

    With any programming task you have to be very precise about the inputs and the outputs...!

    BTW, if you have administrator access to all the hosts, you can access each one in a single BATch file to obtain a NET VIEW using Mark Russinovich's PSEXEC program. But you probably know that already!
  • gaming_guy
    gaming_guy Posts: 6,128 Forumite
    1,000 Posts Combo Breaker
    John_Gray wrote: »
    For each silly face replace it by : p (but without the space between the : and the p, of course!).

    See how it goes!

    or when you are posting, put it in a [code] box or tick the disable smilies in text box

    :):D
  • John_Gray
    John_Gray Posts: 5,845 Forumite
    Part of the Furniture 1,000 Posts Name Dropper Photogenic
    I tried the former, but there seems to be a line-length limit for Code! I will look for the latter,...
  • gaming_guy
    gaming_guy Posts: 6,128 Forumite
    1,000 Posts Combo Breaker
    John_Gray wrote: »
    I tried the former, but there seems to be a line-length limit for Code! I will look for the latter,...

    its under additional options in the reply to thread page.

    hit the quote button and in the reply page that loads, scroll down a bit & it should be there

    :)
  • mr_fishbulb
    mr_fishbulb Posts: 5,224 Forumite
    Part of the Furniture Combo Breaker
    Sorry for not replying yesterday - got completely engrossed in this (didn't leave work until 6.30!).

    To give a bit of background, what I'm trying to write is a script which will:

    1. Find all the domains in my organisation (get that with NET VIEW /DOMAIN).
    2. List all hosts on each domain (get that with NET VIEW /DOMAIN:domainname).
    3. List all shares on each of those hosts (NET VIEW /DOMAIN:domainname \\hostname).
    4. Search through every share for a particular word in a set of file types.

    1 & 2 are fully working now with cleaned-up outputs.
    3 is what I'm working on.
    4 Isn't really going to be used, it's just to practice my scripting ability.
  • stuartk
    stuartk Posts: 245 Forumite
    hi there

    have u used the DSGET or DSQUERY commands?

    regards
  • John_Gray
    John_Gray Posts: 5,845 Forumite
    Part of the Furniture 1,000 Posts Name Dropper Photogenic
    Since you seem to know what you're doing (!), I hope you understood what I was doing in my BATch file and can adapt it accordingly!
  • mr_fishbulb
    mr_fishbulb Posts: 5,224 Forumite
    Part of the Furniture Combo Breaker
    John_Gray wrote: »
    Since you seem to know what you're doing (!), I hope you understood what I was doing in my BATch file and can adapt it accordingly!
    Thanks - think I know what it's doing. I'm going to go back to it this afternoon :)
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 352K Banking & Borrowing
  • 253.5K Reduce Debt & Boost Income
  • 454.2K Spending & Discounts
  • 245K Work, Benefits & Business
  • 600.6K Mortgages, Homes & Bills
  • 177.4K Life & Family
  • 258.8K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.2K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.