判断当前用户是否为root管理员,如果是,则执行tar对/etc/目录执行备份.
#!/bin/bash
# IF current user is root then backup the /etcif [ "$(id -u)" -eq 0 ];then tar -czf /root/etc.tar.gz /etc &>/dev/nullelse echo 'Please switch user on root.' exit 9fi要求用户输入密码,判断密码是否正确.
#!/bin/bash
# Read password and test.read -p "Enter a password:" passwordif [ "$password" == "pass" ];then echo "OK."else echo "Your password is Wrong." exit 9fi九九乘法表
#!/bin/bash
# 九九乘法表for ((i=1;i<=9;i++))do for ((j=1;j<=i;j++)) do echo -n "$j*$i=$[$i*$j] " #printf "%-8s" $j*$i=$(($i*$j)) done echo done批量发送邮件
#!/bin/bash
#批量发送邮件DOMAIN=sharelinux.comfor MAIL_U in tom allen whistledo mail -s "Log" $MAIL_U@${DOMAIN} </var/log/messagedone打印网卡配置文件信息
#!/bin/bash
#Read /etc/sysconfig/network-scripts/ifcfg-eth0 and print out.LINE=/etc/sysconfig/network-scripts/ifcfg-eth0while read -r linedoecho $linedone < $LINE备份MySQL数据库
#!/bin/bash
# This scripts is backup mysql database.DATE=$(date +%Y-%m-%d)DES=/usr/local/src/DB_MySQLMYSQL_U="root" #mysql用户名MYSQL_P="" #mysql密码,需要修改密码MYSQL_H="127.0.0.1" #mysql服务器IP if [ ! -d $DES ];then mkdir -p "$DES"fi#获取数据库名称列表DBS=$(mysql -u${MYSQL_U} -h${MYSQL_H} -Bse 'show databases')#通过循环执行备份所有的MySQL数据库for database in $DBSdo if [ ! "${database}" == "information_schema" ];then mysqldump -u$MYSQL_U -h$MYSQL_H ${database} |bzip2> "${DES}/${database}_${DATE}_mysql.gz" #mysqldump -u$MYSQL_U -P$MYSQL_P -h$MYSQL_H $database|bzip2> "${DES}/${database}_${DATE}_mysql.gz" md5sum ${DES}/${database}_${DATE}_mysql.gz>>${DES}/ReadMe.txt else : fidone