安装expect命令 两种方式

yum安装

yum -y install expect

手动安装

expect以及tcl版本

 

#!/bin/bash
oldpath=`pwd`
tar -zxf tcl8.4.20-src.tar.gz
#3.安装配置
cd tcl8.4.20/unix  
./configure --prefix=/usr/tcl --enable-shared  
make  
make install  
#注意:
#1、安装完毕以后,进入tcl源代码的根目录,把子目录unix下面的tclUnixPort.h copy到子录generic中。
cp ./tclUnixPort.h ../generic/

#(二)expect 安装 (需Tcl的库)

#2.解压缩源码包
cd $oldpath
tar xzf expect5.45.tar.gz  
#3.安装配置
cd expect5.45  
./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib --with-tclinclude=../tcl8.4.20/generic  
make  
make install  
ln -s /usr/tcl/bin/expect /usr/expect/bin/expect
ln -s /usr/tcl/bin/expect /usr/bin/expect

 

testcase

#!/bin/bash
#create hadoop user
user1=$1
useradd $user1

expect -c "
set timeout -1;
spawn passwd $user1;
  expect {
    *password:* {send -- hadoop\r;exp_continue;}
    eof {exit 0;}    
}"
# 更改用户组为root
usermod -g root $user1
#test comand 
# id $user1

 

转载于:https://www.cnblogs.com/rocky-AGE-24/p/7256800.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值