web-dev-qa-db-ja.com

古いユーザーを新しい `/ etc / skel`ファイルで「usermod」するにはどうすればよいですか?

DebianとUbuntuのインストールで古いユーザーを新しい/etc/skelコンテンツで「更新」したいと思います。これをスクリプト化することは可能です...

find /home -maxdepth 1 -mindepth 1 -type d | while read homedir; do
    user="$(stat -c%U $homedir)"
    su -c 'tar -cf- -C /etc/skel . | tar -vxf- -C $HOME' $user
done

...しかし、誰かがより良い方法を知っているかどうか疑問に思っています。

1
rubicks

このようなスクリプトを使用して、ユーザーのディレクトリ内の/etc/skelファイルを更新できます。

#!/bin/bash
#
getent passwd |
    while IFS=: read username x uid gid gecos home Shell
    do
        [[ "$username" == root || ! -d "$home" ]] && continue
        tar -cf - -C /etc/skel . | Sudo -Hu "$username" tar --skip-old-files -xf -
    done

ノート

  • 意図的に、既存のファイルは更新されませんが、ユーザーが削除したファイルを識別できず、それらを再作成して再作成します。
  • rootのファイルはまったく更新されません
2
roaima