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
阅读全文
0 0
- Linux shell 脚本实例
- shell脚本实例解析
- c shell 脚本实例
- shell脚本实例
- shell脚本实例备忘
- Linux shell 脚本实例
- Linux shell 脚本实例
- Linux shell 脚本实例
- shell脚本实例1
- shell脚本实例2
- shell脚本实例0
- shell脚本实例集合
- Shell脚本编程实例
- shell脚本实例
- shell脚本实例解析
- shell脚本实例参考
- Shell脚本实例
- shell脚本实例
- kmemdup
- [SDUT](2134)数据结构实验之栈四:括号匹配 ---栈
- 在Vue项目中使用easyScroll滚动条插件
- HTTPS握手过程与对称加密、非对称加密
- PullToRefreshBase添加头部视图
- shell脚本实例
- Linux下限制IP访问
- Map list的遍历问题
- tcp/ip-路由相关结构
- Android中轮播图的实现
- 二叉树的子树 解题报告
- Python 通过whl后缀安装scipy
- vertical-align属性
- 使用getopt命令解析shell脚本的命令行选项