查看用戶的默認shell
#!/bin/bash
read -p "please type in the user name:" USER
if cat /etc/passwd | cut -d: -f1 |grep ^$USER$ &> /dev/null ;then
cat /etc/passwd |cut -d: -f1,7 |grep $USER |cut -d: -f2
else
echo "do not exist "
fi
read -p "please type in the user name:" USER
if cat /etc/passwd | cut -d: -f1 |grep ^$USER$ &> /dev/null ;then
cat /etc/passwd |cut -d: -f1,7 |grep $USER |cut -d: -f2
else
echo "do not exist "
fi
3個數求最大值
#!/bin/bash
let SUM=0
for I in {1..100} ; do
A=` echo "$I%2"| bc`
if [ $A -eq 0 ];then
let SUM+=$I
else
continue
fi
done
echo "the sum is $SUM"
let SUM=0
for I in {1..100} ; do
A=` echo "$I%2"| bc`
if [ $A -eq 0 ];then
let SUM+=$I
else
continue
fi
done
echo "the sum is $SUM"
修改ip
#!/bin/bash
ifconfig | grep "inet addr" |grep -v "127.0.0.1"
read -p "please type in the ip addr" IP
read -p "please type in the ip mask" MASK
sed -i s/^BOOTPROTO.*/BOOTPROTO=static/g /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i -e 's/IPADDR/#IPADDR/g' -e 's/NETMASK/#NETMASK/g' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i /BOOTPROTO/aIPADDR=$IP /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i /BOOTPROTO/aNETMASK=$MASK /etc/sysconfig/network-scripts/ifcfg-eth0
. /etc/sysconfig/network-scripts/ifcfg-eth0
ifconfig | grep "inet addr" |grep -v "127.0.0.1"
ifconfig | grep "inet addr" |grep -v "127.0.0.1"
read -p "please type in the ip addr" IP
read -p "please type in the ip mask" MASK
sed -i s/^BOOTPROTO.*/BOOTPROTO=static/g /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i -e 's/IPADDR/#IPADDR/g' -e 's/NETMASK/#NETMASK/g' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i /BOOTPROTO/aIPADDR=$IP /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i /BOOTPROTO/aNETMASK=$MASK /etc/sysconfig/network-scripts/ifcfg-eth0
. /etc/sysconfig/network-scripts/ifcfg-eth0
ifconfig | grep "inet addr" |grep -v "127.0.0.1"
pingc/b類ip地址(c類以192.168.0.0網段b類以172.16.0.0網段)
#!/bin/bash
read -p "plesae type in the b/c net " NET
if [ $NET = b -o $NET = B ];then
echo "this a b net"
for I in {1..255};do
for R in {1..255};do
if ping -c1 -W2 172.16.$I.$R &> /dev/null ;then
echo "$I.$R is online."
else
echo "$I.$R is offline."
fi
done
done
elif [ $NET = c -o $NET = C ];then
echo "this is a c net"
for I in {1..255};do
if ping -c1 -W2 192.168.0.$I &>/dev/null ;then
echo"$I is online"
else
echo "$I is offline."
fi
done
else
echo "u r stu"
fi
read -p "plesae type in the b/c net " NET
if [ $NET = b -o $NET = B ];then
echo "this a b net"
for I in {1..255};do
for R in {1..255};do
if ping -c1 -W2 172.16.$I.$R &> /dev/null ;then
echo "$I.$R is online."
else
echo "$I.$R is offline."
fi
done
done
elif [ $NET = c -o $NET = C ];then
echo "this is a c net"
for I in {1..255};do
if ping -c1 -W2 192.168.0.$I &>/dev/null ;then
echo"$I is online"
else
echo "$I is offline."
fi
done
else
echo "u r stu"
fi
求100之類偶數和
#!/bin/bash
let SUM=0
for I in {1..100} ; do
A=` echo "$I%2"| bc`
if [ $A -eq 0 ];then
let SUM+=$I
else
continue
fi
done
echo "the sum is $SUM"
let SUM=0
for I in {1..100} ; do
A=` echo "$I%2"| bc`
if [ $A -eq 0 ];then
let SUM+=$I
else
continue
fi
done
echo "the sum is $SUM"