client_report.sh #1

  • //
  • guest/
  • perforce_software/
  • sdp/
  • dev/
  • Unsupported/
  • Maintenance/
  • client_report.sh
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#!/usr/bin/env bash
#
# client_report.sh - Generate a CSV report of Perforce client workspaces for maintenance review.

usage() {
    cat <<EOF
Usage: $(basename "$0") [-h] [OUTPUT_FILE]

Generate a CSV report of all Perforce client workspaces, including last access date,
owner, and ready-to-run commands for unloading, reloading, or deleting each client.

Useful for identifying stale workspaces and performing bulk cleanup operations.

Arguments:
  OUTPUT_FILE   Path for the output CSV file (default: client_report.csv)

Options:
  -h            Show this help message and exit

Examples:
  $(basename "$0")
  $(basename "$0") /tmp/p4_clients_$(date +%Y%m%d).csv

Requirements:
  - p4 CLI must be in PATH and authenticated
  - 'date' must support the -d flag (GNU coreutils)
EOF
}

# --- Argument parsing ---

while getopts ":h" opt; do
    case $opt in
        h) usage; exit 0 ;;
        \?) echo "Unknown option: -$OPTARG" >&2; usage >&2; exit 1 ;;
    esac
done
shift $((OPTIND - 1))

OUTPUT="${1:-client_report.csv}"

# --- Main ---

echo "Client, Last Access, Owner, Command to unload client, Command to reload client, Command to remove client" > "$OUTPUT"

p4 -ztag -F "%client%|%Access%|%Owner%" clients | while IFS='|' read -r client access owner; do
    if [[ -z "$access" || "$access" == "0" ]]; then
        formatted="N/A"
    else
        formatted=$(date -d "@$access" +"%m/%d/%Y")
    fi
    echo "$client, $formatted, $owner, p4 unload -c $client, p4 reload -c $client, p4 client -d $client"
done >> "$OUTPUT"

echo "Report written to: $OUTPUT"
# Change User Description Committed
#1 32711 Mark Zinthefer Adding reporting scripts client_report.sh and label_report.sh.
Each generates a spreadsheet of all worskapces or labels with last access date, owner, delete, unload, and reload commands.

Client, Last Access, Owner, Command to unload client, Command to reload client, Command to remove client
workspace_1, 05/29/2026, mark, p4 unload -c workspace_1, p4 reload -c workspace_1, p4 client -d workspace_1
workspace_10, 05/29/2026, mark, p4 unload -c workspace_10, p4 reload -c workspace_10, p4 client -d workspace_10
workspace_2, 05/29/2026, mark, p4 unload -c workspace_2, p4 reload -c workspace_2, p4 client -d workspace_2


Label, Last Access, Owner, Command to unload label, Command to reload label, Command to remove label
label_1, 05/29/2026, mark, p4 unload -l label_1, p4 reload -l label_1, p4 label -d label_1
label_10, 05/29/2026, mark, p4 unload -l label_10, p4 reload -l label_10, p4 label -d label_10
label_11, 05/29/2026, mark, p4 unload -l label_11, p4 reload -l label_11, p4 label -d label_11
label_12, 05/29/2026, mark, p4 unload -l label_12, p4 reload -l label_12, p4 label -d label_12
label_13, 05/29/2026, mark, p4 unload -l label_13, p4 reload -l label_13, p4 label -d label_13
label_14, 05/29/2026, mark, p4 unload -l label_14, p4 reload -l label_14, p4 label -d label_14