expect 主要使用场景不输入账户密码的多
yum install -y expect 则可以安装上
#!/usr/bin/expect -f
set username "root"
set password "123456"
spawn /bin/bash
send "cd /data/container/\r"
expect "$ " # 等待命令提示符
send "git pull\r"
expect "Username for 'https://git.baidu.com': "
send "$username\r"
expect "Password for 'https:// u s e r n a m e @ g i t . b a i d u . c o m ′ : " s e n d " username@git.baidu.com': " send " username@git.baidu.com′:"send"password\r"
expect eof
要运行你的脚本,你需要确保它有可执行权限。你可以使用 chmod 命令来添加可执行权限,例如:
chmod +x your_script_name
然后,你可以直接运行此脚本,如下:
./your_script_name
如果你的脚本在当前目录下,你需要在脚本名称前加上 ./。这是因为在 UNIX 和类 UNIX 系统(如 Linux)中,当前目录(.)默认不在系统的 PATH 中,所以你需要明确地指出脚本的位置。
docker
cat /root/dockerin.sh
#!/bin/bash
if [ -z "$1" ]; then
echo "Please provide the container name or ID."
exit 1
fi
docker exec -it "$1" sh
docker rm -f `docker ps -a -q |egrep -v "40f63de1a018|51b19a722d78|1bd3adc940f8|e06a3b307ab4"`
docker rmi `docker images -a -q |egrep -v "db0d0947787d|f462f91720c0|577b86a5e539|7484689f290f|317a302c7480|eeb6ee3f44bd"`
echo "start container"
sh /data/container/project/jn/test/deploy.sh deploy