add expect

This commit is contained in:
nick 2021-04-10 10:22:06 +08:00
parent e2b80e9a66
commit 773b6fcd7f

27
demo.md
View File

@ -2,7 +2,7 @@
新建文件 `vim ~/http.sh` 写入以下内容 新建文件 `vim ~/http.sh` 写入以下内容
``` ```sh
#!/bin/bash #!/bin/bash
ip=xxxxxx #自定义 ip=xxxxxx #自定义
@ -16,7 +16,7 @@ fi
设置定时任务 设置定时任务
``` ```sh
*/10 * * * * ~/http.sh #10分钟执行一次 */10 * * * * ~/http.sh #10分钟执行一次
``` ```
@ -26,7 +26,7 @@ fi
新建文件写入以下内容 新建文件写入以下内容
``` ```sh
#!/usr/bin/env bash #!/usr/bin/env bash
read name read name
@ -47,7 +47,7 @@ fi
新建文件 `vim ~/mysqldump.sh` 写入以下内容 新建文件 `vim ~/mysqldump.sh` 写入以下内容
``` ```sh
#!/bin/bash #!/bin/bash
dir=~/data_bak #自定义 dir=~/data_bak #自定义
@ -66,7 +66,7 @@ fi
设置定时任务 设置定时任务
``` ```sh
1 3 * * 0 ~/mysqldump.sh # 每周日凌晨3点1分执行 1 3 * * 0 ~/mysqldump.sh # 每周日凌晨3点1分执行
``` ```
@ -76,7 +76,7 @@ fi
#### 获取文件名 #### 获取文件名
``` ```sh
#!/bin/bash #!/bin/bash
file_jpg="sample.jpg" file_jpg="sample.jpg"
@ -88,7 +88,7 @@ echo File name is: $name
#### 获取文件扩展名 #### 获取文件扩展名
``` ```sh
#!/bin/bash #!/bin/bash
file="sample.png.text" file="sample.png.text"
@ -99,7 +99,7 @@ echo ${file##*.} #贪婪模式,匹配到最后一个 .
#### 重命名文件 #### 重命名文件
``` ```sh
#!/bin/bash #!/bin/bash
count=1; count=1;
@ -110,4 +110,15 @@ do
mv "$file" "$new_file" mv "$file" "$new_file"
let count++ let count++
done done
```
expect 自动输入密码登录服务器
```sh
#!/usr/bin/expect
spawn ssh username@ip
expect "password:"
send "your_password\r"
interact
``` ```