shell脚本实例

来源:互联网 发布:js触发事件 自动 编辑:程序博客网 时间:2024/05/21 08:01

1.批量创建10个系统账号test01-test10,并随机设置8位数密码

#! /bin/bashfor i in `seq -w 10`do  useradd test$i  echo "$RANDOM" | madsum | cut -c-8 | tee -a passwd.txt --stdin test$i···done

2.在目录/tmp下找到100个以abc开头的文件,然后把这些文件的第一行保存到文件new.txt中。

#! /bin/shfor i in `find /tmp -type f "abc.*"|head -n -100`do  sed -n '1p' >>new.txtdone

3.将/test目录下大于100k的文件移动到/tmp下

#! /bin/shfor file in `find /test -type f -size +100k `do  cd /test &&mv $file  /tmpdone

4.查找最后创建时间是3天前后缀为log并删除

#! /bin/shfind /test -type f -name '*.log' -ctime +3 |xargs rm -f

5.打包并发送邮件

#! /bin/shexport LANG=enfind /bakup/ -name "flag_$(date +%Y)*" |xargs md5sum -c &>>/tmp/mail_$(date +%F).log       #<==写入到tmp下if [ $(date +%w) -eq 1 ]                #<==匹配周一then date=“$(date +%F)_week1"else date="$(date +%F)"fifind /bakup/ -type f -name "*.tar.gz" -a ! -name "*week1" -mtime +7|xargs rm -f           #<==删除超过7天的文件mail -s "bakup_`date`" xxxxxx@xx.com </tmp/mail_$date.log                                 #<==发送邮件

6.自动安装zabbix-agent脚本

#/bin/shrpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpmyum install -y zabbix-agentread -p "input zabbix-agent node:" namesed -i "s/Server=127.0.0.1/Server=192.168.160.50/;s/ServerActive=127.0.0.1/ServerActive=192.168.160.50/;s/Hostname=Zabbix server/Hostname=$name/" /etc/zabbix/zabbix_agentd.confsystemctl enable zabbix-agentsystemctl start zabbix-agent

原创粉丝点击