分类: LINUX
2009-02-09 14:39:00
本章为了兼容性,用Bourne Shell书写。
比如:dd if=/dev/cdrom | ssh remotehost ‘dd of=/opt/big/vmware/sol10.iso’
在测试环境中修改
使之适合你的策略
自动化配置步骤
在测试和部分机器上试验
在所有机器上整体自动化
添加用户的脚本:
# cat adduser_v2.sh
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
REQUIRED_HOST=localhost.localdomain
usage() {
echo "Usage: $0 account_name"
echo "Make sure this is run on the host: $REQUIRED_HOST"
exit 1
}
MYHOSTNAME=`hostname`
[ -n "$1" -a $MYHOSTNAME == $REQUIRED_HOST ] || usage
USERNAME=$1
useradd -m $USERNAME || exit 1
cp /etc/skel/.bash* /home/$USERNAME/ || exit 1
mail -s "Welcome to our site"
${1}@localhost.localdomain <
The SA team has created an account for you on the UNIX systems.
You have a default password that's unique to your account,
which will need to be changed upon initial login.
The system will force this password change.
Please call the SA help desk at 555
password, and to ask any questions that you may have.
EOF
注意系统其实会自动完成这部分:cp /etc/skel/.bash* /home/$USERNAME/ || exit 1。
增加了回滚等错误处理:
# cat adduser_v3.sh
#!/bin/sh
# Written by ncampi
# WARNING!!!! If you attempt to run this for an existing username,
# it will probably delete that user and all their files!
# Think about adding logic to prevent this.
# set the path for safety and security
PATH=/usr/sbin:/bin:/usr/bin
# update me if we fail over or rebuild/rename the admin host
REQUIRED_HOST=localhost.localdomain
usage() {
echo "Usage: $0 account_name"
echo "Make sure this is run on the host: $REQUIRED_HOST"
exit 1
}
die() {
echo ""
echo "$*"
echo ""
echo "Attempting removal of user account and exiting now."
userdel -rf $USERNAME
exit 1
}
MYHOSTNAME=`hostname`
[ -n "$1" -a $MYHOSTNAME == $REQUIRED_HOST ] || usage
USERNAME=$1
useradd -m $USERNAME || die "useradd command failed."
cp /etc/skel/.bash* /home/$USERNAME/ || \
die "Copy of skeleton files failed."
mail -s "Welcome to our site"
${1}@example.net <
The SA team has created an account for you on the UNIX systems.
You have a default password that's unique to your account,
which will need to be changed upon initial login. The system will
force this password change upon your first login.
Please visit the SA help desk in order to receive your password,
and to ask any questions that you may have.
EOF
自动化是切记要注意简单性。