飞天使-linux操作的一些技巧与知识点5-expect与docker便捷命令

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
相关推荐
va学弟7 小时前
Java 网络通信编程(6):视频通话
java·服务器·网络·音视频
幸福指北7 小时前
我用 Tauri + Vue 3 + Rust 开发了这款跨平台网络连接查看工具PortView,性能炸裂!
运维·网络·监控
V__KING__8 小时前
systemd-remount-fs,fstab之间的渊源
linux·服务器·网络
酿情师8 小时前
Windows Subsystem for Linux (WSL, Ubuntu)安装教程(详细)
linux·windows·ubuntu
Titan20249 小时前
Linux环境变量个人笔记
linux·服务器·c++
zx_zx_1239 小时前
传输层协议tcp (2)
服务器·网络·tcp/ip
青柠代码录9 小时前
【Linux】路径区分:testdir、testdir/、testdir/*
linux·运维·服务器
7yewh9 小时前
jetson_yolo_deployment 02_linux_dev_skills
linux·python·嵌入式硬件·yolo·嵌入式
supersolon10 小时前
Windows下WSL(Ubuntu24.04)安装Nodejs
linux·ubuntu·node.js
进击切图仔10 小时前
跨系统时间戳同步问题解决总结
linux