Linux
毛毛鱼公鸡蛋
这个作者很懒,什么都没留下…
展开
-
linux-expect
#!/usr/bin/expectif { $argc != 2 } {puts "Usage: $argv0 "exit 1}set USER [lindex $argv 0]set COMMAND [lindex $argv 1]set prompt “(%|#|\$)”set timeout 3600spawn sudo su - $USERexpect -re promptsend"prompt send "promptsend"COMMAND\r"expect -re原创 2020-10-31 12:16:58 · 48 阅读 · 0 评论 -
shell trap
trap捕捉信号有三种形式第一种:trap “commands” signal-list当脚本收到signal-list清单内列出的信号时,trap命令执行双引号中的命令.第二种:trap signal-listtrap不指定任何命令,接受信号的默认操作.默认操作是结束进程的运行.第三种:trap ’ ’ signal-listtrap命令指定一个空命令串,允许忽视信号.# kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SI原创 2020-09-26 18:55:45 · 192 阅读 · 0 评论 -
curl chek http status code
while truedo status_code=$(curl 'http://localhost:8153/go/api/v1/health' -o /dev/null -w \"%{http_code}\") if [ $status_code == 200 ]; then break fi sleep 10done原创 2020-05-22 13:23:17 · 116 阅读 · 0 评论 -
shell 存入数组
命令输出存入数组:images=($(ls -l|awk '!/localhost/ {n=split($0,A,".");printf "%s=%s\n",$0,A[n]}'))echo ${#images[@]}文件内容存入数组:images=($(cat docker-images.txt))echo ${#images[@]}遍历数组for i in "${images[@]}" ; do echo $i ; donefor i in "${!images[@]}"原创 2020-05-21 09:34:10 · 3885 阅读 · 0 评论 -
shell 字符串分割
str="a,b,c,d"array=(${str//,/ })for var in ${array[@]}do echo $vardone原创 2020-05-11 10:37:57 · 550 阅读 · 0 评论 -
shell 字符串截取
截取分隔符右边的字符串:${var#*/} 截取左边算起第一个“/”右边的所有字符${var#*/} 截取左边算起最后一个“/”右边的所有字符截取分隔符左边的字符串:${var%/*} 截取右边算起第一个“/”左边的所有字符${var%%/*} 截取右边算起最后一个“/”左边的所有字符按字符位置截取字符串:index 从0开始, 负数表示从右边算起的位置${var:index:number} 位置index开始number个字符${var:index} 位置index开原创 2020-05-11 10:23:01 · 279 阅读 · 0 评论 -
shell 输入重定向
1. “< file”从文件中读取输入:while read line; do echo $line; done < server.key2. “<<”称之为 “Here Documents”, 作为文件参数:cat << 'EOF'contents of the fileEOF3. “<<<”称之为 “Here Stri...原创 2020-05-02 12:35:02 · 165 阅读 · 0 评论 -
openssl 自签证书
生成CA证书生成ca秘钥,得到ca.key$ openssl genrsa -out ca.key 4096生成ca证书签发请求,得到ca.csr$ cat << 'EOF' > ca.conf[ req ]default_bits = 4096distinguished_name = req_distinguished_name[ req...原创 2020-05-01 22:28:43 · 318 阅读 · 0 评论 -
yum 源配置
配置yum源1.配置阿里yum源curl http://mirrors.aliyun.com/repo/Centos-7.repo -Omv Centos-7.repo /etc/yum.repos.d/Centos-7.repochown root:root /etc/yum.repos.d/Centos-7.repochmod 644 /etc/yum.repos.d/Centos-...原创 2020-04-28 22:02:19 · 160 阅读 · 0 评论