Skip to content

Instantly share code, notes, and snippets.

@chkp-mkoldov
Created December 29, 2020 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chkp-mkoldov/b030dc7cf5feb5230d4bfd77c4c1377b to your computer and use it in GitHub Desktop.
Save chkp-mkoldov/b030dc7cf5feb5230d4bfd77c4c1377b to your computer and use it in GitHub Desktop.
#!/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="2035-01-01" #setup new desired date in ISO format
# export list of users to file
mgmt_cli -r true show users --format json |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 |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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment