1.7 KiB
1.7 KiB
本文作者:丁辉
Shell脚本集合记录
Shell里有 Read 如何默认回车?
-
示例一
#!/bin/bash defaultValue="默认值" # 如果没有输入,使用默认值 read userInput userInput=${userInput:-$defaultValue} echo "你输入的内容是:$userInput"
执行脚本
bash shell.sh <<< ""
-
示例二
如果有很多 read 需要默认回车
#!/bin/bash defaultValue1="默认值1" defaultValue2="默认值2" echo "请输入内容1:" read userInput1 userInput1=${userInput1:-$defaultValue1} echo "请输入内容2:" read userInput2 userInput2=${userInput2:-$defaultValue2} echo "你输入的内容1是:$userInput1" echo "你输入的内容2是:$userInput2"
执行脚本
bash shell.sh <<< $'\n\n'
如何模拟按钮选择
下载 Shell 示例
wget https://gitee.com/offends/Linux/raw/main/File/Shell/button.sh
Nginx证书签发
下载 Shell 示例
wget https://gitee.com/offends/Linux/raw/main/File/Shell/nginx-ssl.sh
Mysql定时备份脚本
-
创建备份文件存储目录
mkdir -p /opt/mysql/backup && cd /opt/mysql/backup
-
下载脚本
wget https://gitee.com/offends/Linux/raw/main/File/Shell/mysql-backup.sh
修改如下内容
MYSQL_HOST=<MYSQL_HOST> MYSQL_USER=root MYSQL_PASS=root
-
配置计划任务
crontab -e
添加定时任务
0 2 * * * bash /opt/mysql/backup/mysql-backup.sh