#!/usr/bin/perl
# 1. Please change the command to list projects according to your needs (e.g. path to binary, hostname, login, protocol, password)
my $ps_access_command = '"/usr/local/Polyspace_Server/R2020b/polyspace/bin/polyspace-access" -host access.mycompany.org -protocol http -list-project -login admin -encrypted-password ABABABABABABABABABA';
# 2. Please change the location of the output file
my $pscauto_filename = './cleanup.pscauto';
# 3.
$value = qx($ps_access_command);
@lines = grep(/ProjectsWaitingForDeletion\/.*/, split('\n', $value)); # use this for recursive delete
#@lines = grep(/ProjectsWaitingForDeletion\/.* RUN_ID \d+$/, split('\n', $value)); # use this to only delete leaf nodes
@lines = map { s/(.+?)( RUN_ID .*)?$/delete_project \"\1\"/g; $_ } @lines;
open(FH, '>', $pscauto_filename) or die $!;
print FH join("\n", @lines);
close(FH);
print "\n$pscauto_filename successfully written!\n\n";