1、在ftp://192.168.0.254/pub/gls/centes.repo下载到tmp目录
#!/bin/bash
cd /tmp
wget ftp://192.168.0.254/pub/gls/centos.repo
然后再执行bash tmp 即可
2.、判断文件是否存在,是就修改其中的baseurl=htttp://mirrors,163,com/centos.repo为http://mirros.sohu.com/centos 然后将修改后的文件移动到/etc/repos,d/然后再安装
[ -e centos.repo ] && grep "^baseurl=http://mirrors.163.com" centos.repo | sed -i "s/baseurl=http:\/\/mirrors.163.com\/centos\/*/baseurl=http:\/\/mirrors.souhu.com\/centos/g" centos.repo && mv centos.repo /etc/repos.d
&& cd /etc yum install pidgin
3、
一百以内的偶数之和
let i=1
let sum=0
for i in {1..100};do
if [ $[$i%2] -eq 0 ];then
let sum+=$i
fi
let i++
done
echo "the sum is $sum:"
let i=2
[ i=i+2 ] && [ sum+=$i ]
let i++
echo "the sum is $sum"
4.、判断俩个数的大小
if [ $1 -ge $2 ]; then
echo "the max is :$1"
else
echo "the max is :$2"
fi
5、
ping c类网络:
#date: 2010-12-22
for i in {1..10};do
if ping -c1 -W1 192.168.0.$i &> /dev/null;then
echo "$i is online"
echo "$i is offline"
用函数:
~#!/bin/bash
function cping {
NET=`echo "$1" | sed "s/\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/g"`
let i=1
ping -c1 -W1 $NET.$i &> /dev/null
[ $? -eq 0 ] && echo "the $NET.$i is online" || echo "the $NET.$i is outline"
}
read -p "Please input your ip :" MYIP
cping $MYIP