Linux Shell Utility Small instance

Source: Internet
Author: User

  1. 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

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.