Determines whether the current user is the root administrator, and if so, executes the tar to perform a backup of the/etc/directory.
#!/bin/bash
# IF Current user was root then backup the/etc
If ["$ (id-u)"-eq 0];then
Tar-czf/root/etc.tar.gz/etc &>/dev/null
Else
Echo ' Please switch user on root. '
Exit 9
Fi
Ask the user to enter a password to determine if the password is correct.
#!/bin/bash
# Read Password and test.
Read-p "Enter a password:" Password
If ["$password" = = "Pass"];then
echo "OK."
Else
echo "Your password is wrong."
Exit 9
Fi
99 Multiplication Table
#!/bin/bash
# 99 Multiplication Table
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
Send messages in bulk
#!/bin/bash
#批量发送邮件
Domain=sharelinux.com
For Mail_u in Tom Allen whistle
Do
Mail-s "Log" [Email Protected]${domain} </var/log/message
Done
Print NIC profile information
#!/bin/bash
#Read/etc/sysconfig/network-scripts/ifcfg-eth0 and print out.
Line=/etc/sysconfig/network-scripts/ifcfg-eth0
While Read-r line
Do
Echo $line
Done < $LINE
Back up the MySQL database
#!/bin/bash
# This scripts is backup MySQL database.
date=$ (Date +%y-%m-%d)
Des=/usr/local/src/db_mysql
mysql_u= "Root" #mysql用户名
Mysql_p= "" #mysql密码, need to change password
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 $DBS
Do
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
:
Fi
Done
This article is from the "Sanctuary of Calm" blog, please make sure to keep this source http://mastters.blog.51cto.com/6516495/1532939