Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19912810
  • 博文数量: 679
  • 博客积分: 10495
  • 博客等级: 上将
  • 技术积分: 9308
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-18 10:51
文章分类

全部博文(679)

文章存档

2012年(5)

2011年(38)

2010年(86)

2009年(145)

2008年(170)

2007年(165)

2006年(89)

分类: LINUX

2009-02-09 14:39:00

 

       本章为了兼容性,用Bourne Shell书写。

§2.1  一切都是文件

       比如:dd if=/dev/cdrom | ssh remotehost ‘dd of=/opt/big/vmware/sol10.iso’

 

§2.2  理解自动化的过程

       在测试环境中修改

       使之适合你的策略

       自动化配置步骤

       在测试和部分机器上试验

       在所有机器上整体自动化

 

§2.3  探索一个自动化实例

添加用户的脚本:

# 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-1212 in order to receive your

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 05/26/08 for new UNIX user account creation

# 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

 

       自动化是切记要注意简单性。

阅读(3339) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~