飞天使-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
相关推荐
郝学胜-神的一滴17 小时前
Linux命名管道:创建与原理详解
linux·运维·服务器·开发语言·c++·程序人生·个人开发
宾有为17 小时前
【Linux】Linux 常用指令
linux·服务器·ssh
wanhengidc17 小时前
云手机性能如何?
运维·服务器·科技·智能手机·云计算
wdfk_prog17 小时前
[Linux]学习笔记系列 -- [block]bio
linux·笔记·学习
ajassi200017 小时前
开源 Linux 服务器与中间件(十三)FRP服务器、客户端安装和测试
linux·服务器·开源
wan_da_ren18 小时前
Docker安装Elasticsearch9.2.1与Kibana9.2.1 保姆教程(带验证版)
运维·docker·jenkins
Hellc00718 小时前
Docker部署BaGet私有NuGet服务器:从入门到备份恢复完整指南 二
服务器·docker·eureka
XH-hui18 小时前
【打靶日记】群内靶机vm1
linux·网络安全
Eric.Lee202119 小时前
ubuntu 安装 Miniconda
linux·运维·python·ubuntu·miniconda
会飞的土拨鼠呀19 小时前
通过Linux进程id找到程序路径
linux·服务器·网络