#!/bin/bash
# author:huiping
# version:1.0.1
# date:2016-08-11
# describe: 显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
echo "The hosname is: $(hostname)"
echo "The kernel version is: $(uname -r)"
echo "The server_ip is: $( ifconfig |grep 'inet\b' |grep -v '127.0.0.1' |sed 's/.*addr:\b//' |sed 's/Bcast.*//')"
echo "The CPU is: $(lscpu |grep -i 'model name' |tr -s ' ' |sed 's/.*://')"
echo "The OS version is: $(cat /etc/redhat-release)"
echo "The memorysize is: $(free |sed -n '2p' |tr : ' ' |tr -s ' ' |cut -d' ' -f2)"
echo "The disksize is: $(fdisk -l |sed -n '2p')"
[iyunv@localhost bin]# bash -n systeminfometion.sh
[iyunv@localhost bin]# bash systeminfometion.sh
The hosname is: localhost.localdomain
The kernel version is: 2.6.32-642.el6.x86_64
The server_ip is: 10.1.253.35
The CPU is: Intel(R) Core(TM) i3-2350M CPU @ 2.30GHz
The OS version is: CentOS release 6.8 (Final)
The memorysize is: 1004108
The disksize is: Disk /dev/sda: 128.8 GB, 128849018880 bytes
[iyunv@localhost bin]# bash -n systeminfometion.sh
[iyunv@localhost bin]# vim systeminfometion.sh
You have new mail in /var/spool/mail/root
etc_sum=$(ls -A /etc |wc -l)
var_sum=$(ls -A /var |wc -l)
usr_sum=$(ls -A /usr |wc -l)
sumfile=$[$etc_sum+$var_sum+$usr_sum]
echo "The total file is $sumfile"
unset etc_sum
unset var_sum
unset usr_sum
[iyunv@localhost bin]# bash sumfile.sh
The total file is 208
[ $# -ge 1 ] && echo "$1" |egrep -o '(\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.\<(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){2}\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))' &> /dev/null && (ping -c 3 $1 &>/dev/null && echo -e "\e[31m this ip is accessed\e[0m" || echo -e "\e[31m this ip is not accessed \e[0m")
[iyunv@localhost bin]# bash hostping.sh 10.1.1.1
this ip is not accessed
[iyunv@localhost bin]# bash hostping.sh 10.1.253.35
this ip is accessed
[ -r /tmp/file1 -a -w /tmp/file1 ] && echo "Yous can not to read and writ file1"
[iyunv@localhost bin]# bash per.sh
Yous can not to read and writ file1
#!/bin/bash
# author:huiping
# version:1.0.1
# date:2016-08-11
# describe: 接受一个主机的IPv4地址做为参数,先判断是否合格IP,否,提示IP格式不合法并退出,是,测试是否可连通。如果能ping通,则提示用户“该IP地址可访问”; 如果不可ping通,则提示用户“该IP地址不可访问
#!/bin/bash
[ $# -ge 1 ] && echo "$1" |egrep -o '(\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.\<(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){2}\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))' &> /dev/null && (ping -c 3 $1 &>/dev/null && echo -e "\e[31m this ip is accessed\e[0m" || echo -e "\e[31m this ip is not accessed \e[0m")
[iyunv@localhost bin]# bash hostping.sh 10.1.1.1
this ip is not accessed
[iyunv@localhost bin]# bash hostping.sh 10.1.253.35
this ip is accessed