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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With