Ok, I modified the script a tiny bit:
#!/bin/bash
# Created by tvobruba
# version 001
# script is checking and changing expiration date for all internal users in CP MGMT database
# usage: chmod 700 && ./script.sh
date=1609459162000 #setup checked date in ms epoch time - 2020-12-31 16:45
new_date="2036-01-31" #setup new desired date in ISO format
# export list of users to file
mgmt_cli -r true show users --format json --port 4434 |jq '.objects[].name' > list.txt
echo "Checking expiration time of all users..."
echo -e "";
for user in `cat ./list.txt`; do
expiration=`mgmt_cli -r true show user name $user --format json --port 4434 |jq '."expiration-date".posix'`
echo User: $user, $expiration
echo ""
if [ $date \> $expiration ];
then
echo "$user will expire before 31.12.2020 23:55";
echo "Setting new expiration..."
echo ""
mgmt_cli -r true set user name $user expiration-date "$new_date" --format json
else
echo "$user will expire not before: `date -d @$( echo "($expiration + 500) / 1000" | bc)`";
fi;
done
rm -f ./list.txt
The script is now running and it's checking the expiration date of the users that start with letter a, b and c and then it stops.
Example:
"x" will expire not before: Sat Jan 31 00:00:00 CET 2026
User: "x", 1769814000000
"x" will expire not before: Sat Jan 31 00:00:00 CET 2026
User: "x", 1769814000000
"x" will expire not before: Sat Jan 31 00:00:00 CET 2026
User: "x", 1769814000000
"x" will expire not before: Sat Jan 31 00:00:00 CET 2026
User: "x", 1769814000000
"x" will expire not before: Sat Jan 31 00:00:00 CET 2026
We already changed the expiration date of some users to 31-1-2026 (manually).
How to go from here?