随笔分类 -  Shell

摘要:shell> echo -n key | gzip -c | tail -c8 | hexdump -n4 -e '"%u"' | awk '{print $0%1024}' 阅读全文
posted @ 2023-01-12 22:28 wshenJin 阅读(175) 评论(0) 推荐(0) 编辑
摘要:#!/bin/bash ## 创建有名管道文件 [ -e /tmp/fd1 ] || mkfifo /tmp/fd1 ## 创建文件描述符3, 并以可读(<)和可写(>)的方式关联管道文件, 这时文件描述符3就有了有名管道文件的特性 exec 3<>/tmp/fd1 ## 这时候管道文件可以删除 r 阅读全文
posted @ 2022-07-21 15:57 wshenJin 阅读(160) 评论(0) 推荐(0) 编辑
摘要:反解析delete语句 背景:delete table忘了加条件导致整张表被删除 恢复方式:直接从binlog里反解析delete语句为insert进行恢复 导出删指定表的DELETE语句: # mysqlbinlog -vv -d dbname mysql-bin.000048 | awk '/D 阅读全文
posted @ 2019-08-28 12:13 wshenJin 阅读(1770) 评论(4) 推荐(2) 编辑
摘要:很多时候需要批量跑脚本执行任务,但又不想分发再执行,而是直接一条命令下去就跑脚本,该怎么玩比较嗨? 例如以下脚本: 1、管道 s 后面跟的是脚本的参数,如果有。 2、source shell [root@ ~] source 阅读全文
posted @ 2019-03-01 15:39 wshenJin 阅读(2475) 评论(0) 推荐(0) 编辑
摘要:有一段类似以下的文本 希望将上面第二个字段的内容全部替换为 mysql[3306]2018xx 3306xb 一开始,使用下面的命令: 结果导致中间的内容全被替换: 后来改为: 没用,再调整为: 就可以了 第一条命令没有完全精确到想要的字段,第二条命令来看,sed中的 + 似乎需要加个 \\ 在前面 阅读全文
posted @ 2018-10-31 19:35 wshenJin 阅读(208) 评论(0) 推荐(0) 编辑
摘要:去掉最后一个字符 sed 's/.$//' awk '{sub(/.$/,"")}1' awk '{printf $0"\b \n"}' [root@ ~]# echo "387691,387710,387720,387817,387922,388067," 387691,387710,387720 阅读全文
posted @ 2018-09-06 14:06 wshenJin 阅读(212) 评论(0) 推荐(0) 编辑
摘要:由于文本的特殊性,IP字段可能并不是在特定的字段中。 借助awk的match()函数进行匹配截取 awk re interval '($0 ~ "xxx"){match($0,/([0 9]{1,3}\.){3}[0 9]{1,3}/,a);print a[0]}' xxxx.txt match函数 阅读全文
posted @ 2018-03-08 14:46 wshenJin 阅读(730) 评论(0) 推荐(0) 编辑
摘要:一直使用 /dev/urandom 和md5sum的方式去随机字符串,感觉还是不够随机,毕竟只有小写字母和数字嘛。 换换口味: [root@localhost ~] arr=( ) ; str="" ; for i in ; do str=${str}${arr[ ]}; done ; echo $ 阅读全文
posted @ 2018-01-04 16:27 wshenJin 阅读(683) 评论(0) 推荐(0) 编辑
摘要:在某个时间点上增加一段时间 将时间转为时间戳,然后增加时间 [root@~] date +%s d '2017 05 27 12:0:0' 1495857600 [root@ ~] new_time= [root@ ~] echo $new_time 1495862400 [root@ ~] dat 阅读全文
posted @ 2017-05-27 22:47 wshenJin 阅读(797) 评论(0) 推荐(1) 编辑
摘要:redis 3.2.7 安装脚本 for CentOS 6.5 !/bin/bash Filename: inst_for_redis.sh Version: 1.1 Lastdate: 2017/07/25 Author: wangshenjin Description: auto install 阅读全文
posted @ 2017-05-27 14:57 wshenJin 阅读(315) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示