tags:

views:

88

answers:

2

I was going to ask this on superuser.com but there were only 5 perforce tags so I came here... How can I get a list of workspaces on a specific machine with p4?

I can run p4 workspaces, but that gives me all of them, ever. How can I filter it down to a specific machine(client) name.

+3  A: 

Depends on your environment. I've included a basic Windows batch file for doing this.

Run p4 clients. Pull the second word out of each line, that's the client name. Run p4 client -o <name>. Grep for ^Host:.*\b<hostname>\b. If grep returns success, that client is for that machine. Accumulate the list.

In Windows:

set CLIENTS=

for /f "tokens=2" %%c in ('p4 clients') do call :ProcessClient %%c

echo clients on %HOSTNAME% are %CLIENTS%
pause
goto :eof

:ProcessClient
    for /f "tokens=1,2" %%h in ('p4 client -o %1') do if "Host:%HOSTNAME%"=="%%h%%i" set CLIENTS=%CLIENTS% %1
    goto :eof
dash-tom-bang
ahh, I was afraid of that -- I was hoping to limit my query instead of having to return everything and grep for what I was looking for. Thanks though.
Matt
It's not too tough though. :) It's not fast, though, either.
dash-tom-bang
In your second paragraph, do you mean "Run `p4 client -o <name>`", not `workspaces` again? That's what you've got in the batch script.
tenpn
Ah yes, I fell into P4V terminology between writing the batch file and writing this post about it. 'client' and 'workspace' are interchangeable, although yeah in the second case it shouldn't be plural. Will fix.
dash-tom-bang
A: 

I know you specified using P4, but you could also look at P4Report, which gives you SQL query access to Perforce. Once installed, you would just need a query something like:

SELECT clients.client FROM clients WHERE (clients.host='enter your machine here')

which you can also do from the command line (p4sql -s "query string") So if you don't mind substituting P4SQL for P4 in you can me more concise than the script suggested.

P4Report can be found in the Tools & Utilities section of the Perforce Downloads page.

Greg Whitfield