Skip to content

Instantly share code, notes, and snippets.

@mcindea
Last active November 29, 2019 10:01
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 mcindea/11c21a6c9600438877c8f07a982fb13e to your computer and use it in GitHub Desktop.
Save mcindea/11c21a6c9600438877c8f07a982fb13e to your computer and use it in GitHub Desktop.
This script converts DB files created for NSS makedb command while you upgrade from RHEL6 to RHEL7 or 8.
#!/bin/bash
# This script converts DB files created for NSS while you upgrade from RHEL6 to RHEL7 or RHEL8.
# It only happens when you upgrade from RHEL6
# Fixes a problem where the groups are not properly added to the file like the following:
# :john john 2001,2500,4
# First copy the old file to a new file
cp group.tdb group_test.tdb
for line in `grep ^= group.tdb | grep :$ | awk '{print $2}'`; do
GID=`echo $line | cut -d : -f 3`
USER=`echo $line | cut -d : -f 1`
GIDS="$(grep $USER group.tdb | grep : | cut -d : -f 3 | grep ^[0-9] | sort | uniq | tr '\n' , | sed 's/,$//')"
ADD=":$USER $USER $GIDS"
sed -i group_test.tdb -e "/=$GID $line/ a\
$ADD"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment