系统管理脚本实用指南
在Unix或Linux系统管理中,shell脚本是非常实用的工具。下面将详细介绍几个实用的系统管理脚本。
1. 环境验证脚本(validator)
环境验证脚本用于检查用户环境变量的有效性。以下是脚本代码:
if [ ! -d ${HOME:?"You need to have your HOME set to your home directory"} ] then echo "** HOME set to $HOME, but it's not a directory." errors=$(( $errors + 1 )) fi # Our first interesting test: Are all the paths in PATH valid? oldIFS=$IFS; IFS=":" # IFS is the field separator. We'll change to ':'. for directory in $PATH do if [ ! -d $directory ] ; then echo "** PATH contains invalid directory $directory." errors=$(( $errors + 1 )) fi done IFS=$oldIFS # Restore value for rest of script. # The following variables should each be a fully qualified path, # but they may b