Script to remove clients

I have a list of clients

 
$ cat clientlist
 
client1
client2
client3
client4

I need a script to read these clients from a file and list the contanining policies for each client ( one client may belong to more than one policy),

then I'd like to remove the client from all policies they belong to

this the first commamd to list policies for a client

 
bppllist -byclient $CLIENT | grep "CLASS " |  awk '{print $2}' |
 

output

 
 
policy1
policy2

the second command to removed the client from the policy ( one policy per command)

 
bpplclients $POLICY -delete $CLIENT

I will really appreciate your help

Thanks. Sara

Hello ,
You want to do something like that . huh?

for CLIENT in $(cat clientlist)
do
     for POLICY in $(bppllist -byclient $CLIENT | grep "CLASS " |  awk '{print $2}')
     do
          bpplclients $POLICY -delete $CLIENT
     done
done
1 Like

If the list of clients is long, or the client 'name' contains blanks, this would be a better way to read through the list. Also if the output of bpplclients is long the same applies. The grep isn't needed as awk can perform the search so the I/O is reduced.

#!/usr/bin/env bash
while read CLIENT
do
    bppllist -byclient "$CLIENT" | awk '/CLASS/ { print $2; }' | while read POLICY
    do
        bpplclients "$POLICY" -delete "$CLIENT"
    done
done <clientlist

Also note that POLICY and CLIENT are quoted when expanded to allow either to contain blanks.

1 Like