shell小脚本2

一显示统计占用系统内存最多的进程并排序

ps -aux|sort -k4nr |head -n1|awk  '{print $1,$5}'

二、编写脚本,使用for和while分别实现192.168.233.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!"

#!/bin/bash
#Author wuhen
#Date 2019.12.17
Usage(){
echo $"USAGRE:/bin/bash ip address "
exit 1
}
#$# 是传给脚本的参数个数
if [ "$#" -ne "0" ];then
Usage
fi
PING="ping -w 2 -c 2"
IP="192.168.233"

    for n in `seq 1 254`
     do
       {
           $PING $IP.$n &> /dev/null
           if [ $? -eq 0 ];then
               echo "$IP.$n is sucess"
           else
           echo "$IP.$n is fail"
            fi
         }&    #shell的并发检测,批量ping
      done
#!/bin/bash
#Author wuhen
#Date 2019.12.17
Usage(){
echo $"USAGRE:/bin/bash ip address "
exit 1
}
#$# 是传给脚本的参数个数
if [ "$#" -ne "0" ];then
Usage
fi
PING="ping -w 2 -c 2"
IP="192.168.233"
#定义最后一位
i=1
     
    while [ $i -le 254 ];do
       {
          $PING $IP.$i &> /dev/null
           if [ $? -eq 0 ];then
           
               echo "$IP.$i is sucess"
           
           else
           
               echo "$IP.$i is fail"
           
           fi
         }&    #shell的并发检测,批量ping
          #自增
           let i++
     done


每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式 为“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的时间

#backup.sh内容
tar -zcvf /backup/etcbak-$(date -d  "1 day ago" +"%F-%H").tar.xz  /etc/ &>/dev/null

#crontab 内添加此条计划任务
30 1  * * 1-5 sh backup.sh
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值