1、显示统计占用系统内存最多的进程,并排序。
[root@VM-0-17-centos ~]# ps aux|awk '{print $4,$2,$11}'|sort -rn|head -20 5.0 1748 /usr/local/qcloud/YunJing/YDEyes/YDService 2.5 589 /usr/lib/systemd/systemd-journald 1.7 811 /usr/libexec/sssd/sssd_nss 1.6 1077 /usr/sbin/rsyslogd 0.8 925 /usr/libexec/platform-python 0.8 490358 barad_agent 0.8 1764 /usr/local/qcloud/YunJing/YDEdr 0.6 490357 barad_agent 0.6 1740 /usr/local/qcloud/YunJing/YDLive/YDLive 0.5 764 /usr/lib/polkit-1/polkitd 0.5 2426822 sshd: 0.5 2426813 /usr/lib/systemd/systemd 0.5 2426805 sshd: 0.5 2423196 pickup 0.5 2363972 qmgr 0.4 803 /usr/libexec/sssd/sssd_be 0.4 490339 barad_agent 0.4 1 /usr/lib/systemd/systemd 0.3 2426842 sshd: 0.3 2426823 sshd: [root@VM-0-17-centos ~]# ps aux --sort -%mem|head -5 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1748 0.1 5.0 1040708 95404 ? Sl Apr20 85:05 /usr/local/qcloud/YunJing/YDEyes/YDService root 589 0.0 2.5 162840 47772 ? Ss Apr20 1:11 /usr/lib/systemd/systemd-journald root 811 0.0 1.7 221336 31868 ? S Apr20 7:55 /usr/libexec/sssd/sssd_nss --uid 0 --gid 0 --logger=files root 1077 0.0 1.6 465432 30080 ? Ssl Apr20 1:55 /usr/sbin/rsyslogd -n
2、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!"
IP="192.168.0" I=1 for I in `seq 255`;do { if ping -w -l -c1 $IP.$I &>/dev/null;then echo "the $IP.$I is success!" else echo "the $IP.$I is fail!" fi }& done wait --------------------------------------------------------------------------------- ip="192.168.0" i=1 while [ $i -le 255 ];do { if ping -w -l -c1 $ip.$i&> /dev/null;then echo "the $ip.$i is success!" else echo "the $ip.$i is fail!" fi }& let i++; done wait
3、每周的工作日1:30,将/etc备份至/backup目录中,保存的文件名称格式 为“etcbak-yyyy-mm-dd-HH.tar.xz”,其中日期是前一天的时间
//bash脚本命令 DIR="/data/backup" date=`date -d -1day +"%F-%H"` bakdir=/data/backup/etcbak-$date cp -a /etc $bakdir &>/dev/null tar -cvf $bakdir.tar.xz $bakdir &>/dev/null [root@VM-0-17-centos test]# crontab -l //编辑文件,创建周期性任务 --其格式为 分 时 天 月 周(0-7) [root@VM-0-17-centos test]# crontab -l //查询周期性任务 */5 * * * * flock -xn /tmp/stargate.lock -c '/usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &' 30 01 * * 0 /usr/bin/bash /data/test/backup.sh
发生
df -h|sed -En '\/dev\/vda/p'|awk -F' +|%' '{if ($5>=0) {print $1,$5}}'|while read DEVICE USE;do [ $USE -gt 5 ] && echo "$DEVICE disk is be full ,Used $USE" done [root@VM-0-17-centos test]# crontab -l */5 * * * * flock -xn /tmp/stargate.lock -c '/usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &' 30 01 * * 0 root /data/test/backup.sh */10 * * * 1-5 root /data/test/disk.sh