[root@centos7 ~]#cat create.sh
#!/bin/bash
[ $# -ne 2 ] && { echo Usage:$0 username home-dir; exit 1; }
if [ ! -d $2 ];then
mkdir -p $2 || { echo syntax error;exit 10; }
fi
id $1 &> /dev/null && echo user $1 is exist! || { useradd -d /www $1 &> /dev/null && echo user $1 is created and home-dir is $2; }
# 执行结果
[root@centos7 ~]#./create.sh
Usage:./create.sh username home-dir
[root@centos7 ~]#./create.sh magedu /www
user magedu is created and home-dir is /www
[root@centos7 ~]#./create.sh magedu /www
user magedu is exist!
[root@centos7 ~]#cat expect.sh
#!/usr/bin/expect
set ip [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn ssh $user@$ip
expect {
"yes/no" {send "yes\n";exp_continue}
"password" {send "$password\n"}
}
interact
# 执行结果
[root@centos7 ~]#./expect.sh 192.168.131.131 root 123456
spawn ssh root@192.168.131.131
root@192.168.131.131‘s password:
Last login: Sun Jun 21 15:17:47 2020 from 192.168.131.1
Hello!!!
[root@CentOS6 ~]#
说明:这里的rd.break可以改为rw init=/sysroot/bin/sh,此时不需要执行下面的重新挂载命令,因为已经通过rw方式挂载了根目录
mount -o remount,rw /sysroot
chroot /sysroot
passwd root
原文:https://www.cnblogs.com/kfscott/p/13173991.html