Shell Basics Using Notes

Source: Internet
Author: User
Tags stdin

Create 10 user user1-user10;
[Email protected] ~]# vim user.sh
#!/bin/bash #注释为bash
For ((i=1;i<=10;i++))#条件
Do #动作
Useradd user$i # Add user, $i as variable (i=i+1, always execute to i<=10)
echo "User$i" | passwd--stdin user$i #打印出来, create user password consistent with user name

echo "Jiejie" | passwd--stdin user10# to the user user10 password for Jiejie;
Done #完成

[Email protected] ~]# vim file.sh
#!/bin/bash
Touch file{10 . #创建10个空文件file10-file19


Print 99 multiplication table
[Email protected]Mini ~]# vim multiplicationtable.sh
#!/bin/bash
For ((i=1;i<=9;i++))#条件语句

Do
For ((j=1;j<= $i; j + +))#条件语句
Do
ECHO-E-N "$j * $i =$[$i * $j]\t" #显示以行为首
Done
echo ""
Done


[email protected] ~]#Vim passwd.sh
#!/bin/bash
Read-p "Please input your password >" num #交互式
echo "Your password $num"

Every two hours every day take all the information in the current system/proc/meminfo file to the/stats/memory.txt file
[[Email protected]Mini ~]# Mkdir/stats; Touch Memory.txt
[[Email protected]Mini ~]# CRONTAB-E
1 */2 * * * grep-e "^s"/proc/meminfo >>/stats/memory.txt


Write a script that uses the ping command to detect the online status of all hosts between 192.168.0.1-192.168.0.254;
The online host uses green display;
#!/bin/bash
Ipaddr= "192.168.0."
For i in {1..254}
Do
Ping-c 1 $ipaddr $i &>/dev/null;
If [$?-eq 0]
Then
Echo-e "\e[1;32m$ipaddr$i\e[0m"
Else
Echo-e "\e[1;41m$ipaddr$i\e[0m"
Fi
Done
echo Options:
When using the-e option, if the following characters appear in the string, they are handled in particular, not as general text output:
\a issued a warning sound;
\b Delete the previous character;
\c finally not add the line break symbol;
\f the line but the cursor remains in its original position;
\ n Wraps and the cursor moves to the beginning of the line;
\ r The cursor moves to the beginning of the line, but does not wrap;
\ t Insert tab;
\v is the same as \f;
\ \ insert \ character;
\NNN inserts the ASCII character represented by the NNN (octal);


Read option

-P: Specifies the prompt to read the value;

-T: Specifies the time to wait (in seconds) to read the value




Shell Basics Using Notes

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.