List workspaces of a user on a specific machine in Perforce
Asked Answered
H

3

6

How can I get all Perfoce workspaces of a specific user on a specific machine?

This command let me all workspaces of a specific user on all machines:

P4 clients -u username
Harvey answered 16/1, 2014 at 11:17 Comment(1)
Often there's no single command that gives you exactly what you want, but a simple script that combines several commands does the trick. What's your preferred scripting language for building tools like these? That will make it easier for people to help you. Also, what have you tried so far, and where did you run into trouble?Megass
B
3

Here's a cmd one-liner that does more or less the same thing as pitseeker's:

for /f "tokens=2" %x in ('p4 clients -u username') do @(echo %x & p4 client -o %x | findstr /r /c:"^Host:")

A somewhat more robust batch file that seems to fit what you're looking for is:

@echo off
set USER=%1
set HOST=%2
REM Don't forget to double your for-loop percents in batch files,
REM unlike the one-liner above...
for /f "tokens=2" %%x in ('p4 clients -u %USER%') do call :CheckClient %%x
goto :EOF

:CheckClient
p4 client -o %1 | findstr /r /c:"^Host:" | findstr /i /r /c:"%HOST%$">nul && echo %1
goto :EOF

Save that and run it with the username as the first parameter and the desired host name as the second. That is, something like showclient elady elady_pc

Berns answered 17/1, 2014 at 17:50 Comment(1)
Thanks! that's what I looked for. (It neatly works due to the fact that workspace name with spaces is not allowed)Harvey
R
2

Not exactly what you're asking for, but it's easy and perhaps sufficient:

p4 clients -u username | cut -f2 -d' ' | xargs -n 1 p4 client -o  |egrep -e '^Client|^Host'

This lists all your clients and their host-restrictions (if any). In the resulting list you can find the specific machines very easily.

Reflate answered 16/1, 2014 at 13:6 Comment(1)
Sorry I didn't mention before, I'm working on Windows, so I can't use 'cut' or 'egrep' commandsHarvey
S
0

The following command returns the host name without an additional time-intensive call to p4 client for each client, by using a custom output formatter:

p4 clients -ztag -F '%client% %Host%' clients -u username

You can then parse the output using a scripting language of your choice, e.g. Powershell:

p4 clients -ztag -F '%client% %Host%' clients -u username | Select-String " hostname"

(note the space)

To get a list of the available formatting fields that -F can use, run the command with the "-e" or -ztag global options.

https://portal.perforce.com/s/article/15148

Suzannsuzanna answered 2/5, 2024 at 11:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.