Linux系统管理中的实用Shell脚本
1. 清理访客账户脚本(fixguest)
在多人共享同一访客账户的情况下,很容易出现账户空间被弄乱的问题,比如有人可能在尝试命令、编辑.rc文件、添加子目录等,给下一个用户带来不便。fixguest脚本可以在用户从访客账户注销时清理账户空间,解决这个问题。
代码实现:
#!/bin/bash # fixguest--Cleans up the guest account during the logout process # Don't trust environment variables: reference read-only sources. iam=$(id -un) myhome="$(grep "^${iam}:" /etc/passwd | cut -d: -f6)" # *** Do NOT run this script on a regular user account! if [ "$iam" != "guest" ] ; then echo "Error: you really don't want to run fixguest on this account." >&2 exit 1 fi if [ ! -d $myhome/..template ] ; then echo "$0: no template directory found for rebuilding." >&2 exit 1 fi