Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of workspaces on a specific machine with p4

Tags:

perforce

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.

like image 666
Matt Avatar asked May 15 '10 00:05

Matt


2 Answers

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
like image 107
dash-tom-bang Avatar answered Oct 01 '22 19:10

dash-tom-bang


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.

like image 20
Greg Whitfield Avatar answered Oct 01 '22 20:10

Greg Whitfield