报错代码:
mount error(13) permission denied
解决思路:通过 dmesg 命令查看 kernel log 从确定问题出在哪里
# dmesg
......
mount error(13) permission denied
# dmesg
......
在使用 spawn 参数之前,要先安装 expect
设置 expect 参数等待执行的时间 (默认是 30 秒) 或者其它变量
#!/bin/bash
set timeout 30
或者:
#!/usr/bin/expect
set timeout 30
(补充:这里以设置 expect 参数的等待时间为 30 秒为例)
脚本开始根据出现的输出自动执行命令
#!/bin/bash
expect << EOF
spawn ssh mingyuzhu@10.0.0.1
expect "password:" {send "123\r"}
expect ">" {send "\r"}
EOF
或者:
#!/usr/bin/expect
spawn ssh mingyuzhu@10.0.0.1
expect {"password:" {send "123\r"}}
expect eof
(补充:这里以使用 mingyuzhu 用户通过 SSH 登录 IP 地址为 10.0.0.1 的服务器,同时当输出的最后的字段是 “password:” 时自动输入 “123” 并回车为例)
后面接预期出现的内容。可以跟 send 参数配合,实现出现预期内容后执行什么命令,也可以不跟 send 参数配合只是出现什么内容后直接退出
#!/bin/bash
expect << EOF
spawn ssh mingyuzhu@10.0.0.1
expect "password:" {send "123\r"}
expect ">" {send "\r"}
EOF
或者:
#!/usr/bin/expect
spawn ssh mingyuzhu@10.0.0.1
expect {"password:" {send "123\r"}}
expect eof
(补充:这里以使用 mingyuzhu 用户通过 SSH 登录 IP 地址为 10.0.0.1 的服务器,同时当输出的最后的文本是 “password:” 时自动输入 “123” 并回车为例)
#!/usr/bin/expect
spawn ssh mingyuzhu@10.0.0.1
expect {
\"Linux*\" { exit 200 }
timeout { exit 100 }
incorrect { exit 100 }
eof { exit 100 }
}
return $?
interact
expect eof
(
补充:
1) 这里以使用 mingyuzhu 用户通过 SSH 登录 IP 地址为 10.0.0.1 的服务器
2) 同时当输出的最后的文本是以 “Linux” 开头时,返回值是 200,超市或其他的返回值是 100
3) 并最后将控制权还给用户为例
)
后面接要执行的命令。当预期出现的内容出现后,执行这些命令
#!/bin/bash
expect << EOF
spawn ssh mingyuzhu@10.0.0.1
expect "password:" {send "123\r"}
expect ">" {send "\r"}
EOF
或者:
#!/usr/bin/expect
spawn ssh mingyuzhu@10.0.0.1
expect {"password:" {send "123\r"}}
expect eof
(补充:这里以使用 mingyuzhu 用户通过 SSH 登录 IP 地址为 10.0.0.1 的服务器,同时当输出的最后的字段是 “password:” 时自动输入 “123” 并回车为例)
代表结束所有,如果没有 EOF 的话最后的命令可能不会执行完
#!/bin/bash
expect << EOF
spawn ssh mingyuzhu@10.0.0.1
expect "password:" {send "123\r"}
expect ">" {send "\r"}
EOF
或者:
#!/usr/bin/expect
spawn ssh mingyuzhu@10.0.0.1
expect {"password:" {send "123\r"}}
expect eof
(补充:这里以使用 mingyuzhu 用户通过 SSH 登录 IP 地址为 10.0.0.1 的服务器,同时当输出的最后的字段是 “password:” 时自动输入 “123” 并回车为例)
代表结束自动交互,就是把控制权交给用户
#!/bin/bash
expect << EOF
spawn ssh mingyuzhu@10.0.0.1
expect "password:" {send "123\r"}
expect ">" {send "\r"}
EOF
或者:
#!/usr/bin/expect
spawn ssh mingyuzhu@10.0.0.1
expect {"password:" {send "123\r"}}
expect eof
(补充:这里以使用 mingyuzhu 用户通过 SSH 登录 IP 地址为 10.0.0.1 的服务器,同时当输出的最后的字段是 “password:” 时自动输入 “123” 并回车为例)
SIOCADDRT: File Exists
确保以下目录中,网卡配置文件的 IP 地址只出现过了 1 次
/etc/sysconfig/network-scripts
# loginctl -a
SESSION UID USER SEAT TTY
27 1001 mingyuzhu pts/0
(
补充:从输出结果可以看出
1) 会话\进程的 SESSION 号码为 27
2) 创建会话\进程的用户 UID 是 1001
3) 创建会话\进程的用户是 mingyuzhu
4) 创建会话\进程的 SEAT TTY 是 pts/0
)
# loginctl terminate-session 27
(补充:这里以关闭 SESSION 号码是 27 的会话\进程为例)
# loginctl -a | grep mingyuzhu| awk '{print "loginctl terminate-session "$1;system("loginctl terminate-session "$1"")}'
# loginctl -a | grep mingyuzhu| awk '{print "loginctl terminate-session "$1;system("loginctl terminate-session "$1"")}' > /dev/null
或者:
# loginctl -a | grep mingyuzhu| `awk '{print "loginctl terminate-session "$1;system("loginctl terminate-session "$1"")}'`
[error] [/....../system-auth] has unexpected content!
[error] [/....../password-auth] has unexpected content!
[error] [/....../nsswitch.conf] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.
Some unexpected changes to the configuration were detected. Use 'select' command instead.
# mv /etc/authselect/custom/password-policy /etc/authselect/custom/password-policy-backup
# authselect create-profile password-policy -b sssd --symlink-meta --symlink-pam
# authselect select custom/password-policy with-sudo with-faillock without-nullok with-mkhomedir --force
# dnf install oddjob ; systemctl enable --now oddjobd.service
# authselect apply-changes