Linux shell scripting Exercises

Source: Internet
Author: User
Tags stdin

One

#!/bin/bash
#自动添加用户, and make the initial password a user account name, and force the user to change the password when they log on
I=1
While [$i-le 15]
Do
If [$i-le 9]
Then
Useradd user0$i
echo "User0$i" | passwd--stdin user0$i &>/dev/null
chage-d 0 user0$i
Else
Useradd user$i
echo "User$i" | passwd--stdin user$i &>/dev/null
chage-d 0 user$i
Fi
# Userdel-r User$i

Let i++
Done


#!/bin/bash
#检测当前系统任一服务状态, start it if it is not started.
Read-p ' Input a service name: ' Ser
Service $ser Status &>/dev/null
If [$?-eq 0];
Then
echo "Service is running."
# elif [$?-eq 3];
# then service $ser start
Else
Service $ser Start

Fi



#!/bin/bash
#输出30至80之间的偶数及统计个数
G=0

For i in {30..80}
Do
yu= ' expr $i% 2 '

If [$yu-eq 0]
Then Echo-n ' $i ' && let g++
Fi
Done
Echo
echo "There is $g even totally."



#!/bin/bash
#阶乘运算
Read-p ' Input a number: ' num
Cj=1
For ((i=1;i<= $num; i++))
Do
Let Cj*=i
Done
Echo $CJ


#!/bin/bash
#生成九九乘法表
For ((i=1;i<=9;i++))
Do
For ((j=1;j<=i;j++))
Do
abc= ' expr $i \* $j '
Echo-n "$j * $i = $ABC"

Done

Echo
Done



#!/bin/bash
#备份MySQL日志
Dir=/var/lib/mysql
index= $dir/localhost-bin.index
I= ' Cat $index | Wc-l '
i=$ (($i-1))

if [!-e/logbackup]
Then Mkdir/logbackup
Fi

For log in ' head-$i $index | Awk-f '/' {print $} '
Do CP-NV $dir/$log/logbackup
Done


#!/bin/bash
#检测192.168.1.0/24 network segment and record IP address information that is not in line
net=192.168.1.
#for I in 1 2 3 4 5 6 7 8 9 10
#for i in ' seq 254 '
For I in {A.. Z
Do
Ping-c 3 $net $i &>/dev/null
If
[$?-eq 0]
Then
echo "$net $i is online!!!"
Else
echo "$net $i is offline!!!"
Fi
Done

This article is from the "Paundudo" blog, make sure to keep this source http://paundudo.blog.51cto.com/3741758/1538738

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.