标签:linu cat 重定向 网页 release 不执行 eth pdu ret
1.每12小时备份并压缩/etc/目录到/data中,并保存文件格式为“etc-年-月-日-时-分.tar.gz”编写脚本用来备份 文件/root/etcback.sh
#!/bin/bash
tar -zcf /data/etc-`date "+%F-%H-%M"`.tar.gz /etc/ &>/dev/null
确保crond服务启动 ps -aux|grep cron
root 971 0.0 0.1 126304 1564 ? Ss 13:18 0:00 /usr/sbin/crond -n
root 5393 0.0 0.0 123252 760 ? Ss 15:01 0:00 /usr/sbin/anacron -s
创建自己的yum仓库
进入. /etc/yum.repos.d/ 建立base.repo文件
[base]
name=carom
baseurl=file:///misc/cd/
gpgkey=file:///misc/cd/RPM-GPG-KEY-CentOS-$releaserver
[network]
name=all
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/x86_64/
enabled=1
gpgkey=https://mirrors.aliyun.com/centos/$releasever/os/x86_64/RPM-GPG-KEY-CentOS-$releasever
禁用network yum源时改为enabled=0
[root@centos7 ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base network
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
[root@centos7 ~]#yum repolist
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
network | 3.6 kB 00:00:00
(1/4): base/group_gz | 156 kB 00:00:00
(2/4): base/primary_db | 5.7 MB 00:00:00
(3/4): network/7/group_gz | 166 kB 00:00:01
(4/4): network/7/primary_db | 6.0 MB 00:00:05
Determining fastest mirrors
repo id repo name status
base carom 9,591
network/7 all 10,019
repolist: 19,610
#!/bin/bash
disk () {
df -h
echo ""
lsblk
}
mem () {
free -h
echo ""
cat /proc/meminfo
}
cpu (){
iostat -c
echo ""
cat /proc/cpuinfo
}
f_wait () {
echo ""
read -p "please input any key to continue !" key
case $key in
*)
continue
;;
esac
}
while true ;do
echo -e "(1)disk:show disk info\n"
echo -e "(2)mem: show memory info\n"
echo -e "(3)cpu: show cpu info!\n"
echo -e "(*) quit\n "
read -p "please input your selection (1-3): " num
case $num in
1)
disk
f_wait
;;
2)
mem
f_wait
;;
3)
cpu
f_wait
;;
*)
echo "exit........"
sleep 1
exit
esac
done
测试:
root@centos7 testsh]#bash sysmenu.sh
(1)disk:show disk info
(2)mem: show memory info
(3)cpu: show cpu info!
(*) quit
please input your selection (1-3): 1
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 50G 8.8G 42G 18% /
devtmpfs 576M 0 576M 0% /dev
tmpfs 591M 0 591M 0% /dev/shm
tmpfs 591M 8.5M 582M 2% /run
tmpfs 591M 0 591M 0% /sys/fs/cgroup
/dev/sda3 30G 75M 30G 1% /data
/dev/sda1 1014M 158M 857M 16% /boot
/dev/sdb1 9.8G 13M 7.8G 1% /mydata
tmpfs 119M 12K 119M 1% /run/user/42
tmpfs 119M 0 119M 0% /run/user/0
/dev/sr0 8.1G 8.1G 0 100% /misc/cd
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 50G 0 part /
├─sda3 8:3 0 30G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sdb 8:16 0 60G 0 disk
├─sdb1 8:17 0 10G 0 part /mydata
└─sdb2 8:18 0 1G 0 part [SWAP]
sdc 8:32 0 30G 0 disk
├─sdc1 8:33 0 10G 0 part
├─sdc2 8:34 0 10G 0 part
│ └─testvg-testlv 253:0 0 3G 0 lvm
└─sdc3 8:35 0 10G 0 part
sr0 11:0 1 8.1G 0 rom /misc/cd
please input any key to continue !
(1)disk:show disk info
(2)mem: show memory info
(3)cpu: show cpu info!
(*) quit
please input your selection (1-3): q
exit........
sed是一种流编辑器,它一次处理一行内容。处理时,把当前 处理的行存储在临时缓冲区中,称为“模式空间”,接着用sed命令处理缓冲区中的内容,处理完成后 ,把缓冲区的内容送往屏幕。然后读入下行,执行下一个循环 。如果没有使诸如‘D’的特殊命令,那会在两个循环之间清空 模式空间,但不会清空保持空间(高级用法时候使用)。这样不断重复,直到文件末 尾。文件内容并没有改变,除非你使用重定向存储输出。
[^A-Za-z0-9_ ] 方法可以使用在排除特殊字符
#!/bin/bash
dirpath=/var/log/httpd/access_log
while read line ; do
sta=`echo $line |sed -rn "s/.*\" ([0-9]+) .*/\1/p"`
if [ $sta -ge 400 ] ;then
echo $line |sed -rn "s/(.*) - -.*/\1/p" >> ./httpdstat
fi
done <$dirpath
cat ./httpdstat|sort -rn|uniq -c|sort -rn
rm -f ./httpdstat &>/dev/null
安装httpd服务,启动httpd服务,用不同ip访问网页产生错误和正常日志文件
执行脚本
[root@centos7 testsh]#bash httpdstatic.sh
354 192.168.0.101
18 192.168.0.108
15 192.168.0.111
3 192.168.0.112
执行命令批量安装服务
yum -y install ftp tcpdump openssh
后面提示
Installed:
ftp.x86_64 0:0.17-67.el7 openssh.x86_64 0:7.4p1-16.el7 tcpdump.x86_64 14:4.9.2-3.el7
Complete!
成功安装
标签:linu cat 重定向 网页 release 不执行 eth pdu ret
原文地址:http://blog.51cto.com/6289984/2331142