shell脚本实例

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

#! /bin/bash
for 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/sh
for i in `find /tmp -type f "abc.*"|head -n -100`
do
  sed -n '1p' >>new.txt
done

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

#! /bin/sh
for file in `find /test -type f -size +100k `
do
  cd /test &&mv $file  /tmp
done

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

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

5.打包并发送邮件

#! /bin/sh
export LANG=en
find /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)"
fi

find /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/sh
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
yum install -y zabbix-agent
read -p "input zabbix-agent node:" name
sed -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.conf
systemctl enable zabbix-agent
systemctl start zabbix-agent

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值