侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

20170213--随机密码+xrags+文件锁

2023-11-22 星期三 / 0 评论 / 0 点赞 / 64 阅读 / 3311 字

随机密码小程序 方法一: [kate@up12 ~]$ ./random+0213.sh 1cbda11c32[kate@up12 ~]$ cat random+0213.sh #!/bin/bash

随机密码小程序

方法一:

[kate@up12 ~]$ ./random+0213.sh 1cbda11c32[kate@up12 ~]$ cat random+0213.sh #!/bin/bash#随机密码的生成#rand=(0 1 2 3 a b c d "@")len=${#rand[*]}for ((i=0;i<10;i++));do    rnum=$((RANDOM%len))    echo -n "${rand[rnum]}"doneecho

方法二:

  1 #!/bin/bash  2 # 随机密码的生成  3 # openssl passwd -apr1 uplooking | cut -c16-27  4 # openssl passwd -apr1 uplooking | tail -c 9  5   6 aa=$1  7   8 genpasswd() {  9     local l=$1 10     : ${l:=20} 11     #[ -z "$l" ] && l=20 12     tr -dc 'A-Za-z0-9_,.!@#$%^&*()' < /dev/urandom | head -c ${l} 13     echo 14     #tr -dc 'A-Za-z0-9_)' < /dev/urandom | head -c ${l} | xargs 15     #tr -dc 'A-Z' < /dev/urandom | head -c ${l} | xargs 16 } 17  18 genpasswd $aa#tr -dc 表示不删除后面的内容  /dev/urandom是一个随机数的文件

 

方法三:直接使用openssl命令

[kate@up12 ~]$ openssl passwd -apr1 uplooking | cut -c16-27
kKBZg5QUk4Cu
[kate@up12 ~]$ openssl passwd -apr1 uplooking | tail -c 9
/Uisfsv.
 

xargs

find . -empty //查找空文件
find . -empty -exec rm- rf{} /; //删除空文件
find . -empty |xargs ls -l //xargs 得到前一条命令的结果
[kate@up12 ~]$ cat txt/1.txt |xargs -I{} echo {}#{}123 >txt/3.txt //-I的作用是用{}代表上一条命令的结果
sed -i 's/$/&#/g' 1.txt //这条命令的作用也是给每行末尾加上一个#号

[kate@up12 shell-scripts]$ find . -empty | xargs -I{} cp {} /tmp/backup/

123+234+456+88+100+22+[kateecho "hello123world234abc456cc88dd100ee22" |grep -oP '[0-9]+' | tr '/n' '+' |xargs -I{} echo {}0 123+234+456+88+100+22+0[kate@up12 shell-scripts]$ echo "hello123world234abc456cc88dd100ee22" |grep -oP '[0-9]+' | tr '/n' '+' |xargs -I{} echo {}0 |bc1023[kate@up12 shell-scripts]$ echo "hello123world234abc456cc88dd100ee22" |grep -oP '[0-9]+' 1232344568810022[kate@up12 shell-scripts]$ 

 

 

 

wait


wait //等待前面的所有后台的任务都完成后,才执行退出。并行执行多个任务

文件锁--当程序只能由一个实例运行的时候

 

程序1:

  1 #!/bin/bash  2 #文件锁的使用  3 #  4   5 [ $UID != 0 ] && echo "请使用超级用户运行!" && exit 1  6   7 . /ect/init.d/functions  8   9 echo "备份开始..." 10 tar czf /tmp/backup/etc.tar.gz /etc 11 if [ $? = 0 ] ;then 12     success "备份成功!" 13     echo 14 else 15     failure "备份失败!" 16     echo 17 fi~           

 

程序2:

 

 

 

 

广告 广告

评论区