Write a script:
1. Create a directory/tmp/scripts
2. Switch the working directory to this directory.
3. Copy the/etc/PAM. d directory to the current directory and run the test command again.
4. Change the owner of test and its files and subdirectories to RedHat.
5. Change the permissions of other users of files in the test and its subdirectories to No permissions.
#! /Bin/bash
#
Dir = '/tmp/csripts2'
Mkdir $ dir
CD $ dir
CP-RF/etc/PAM. D./test
Chown-r RedHat./test
Chmod-R o = ---./test
Ls-LR $ dir
Unset dir
--------------------------------------------------------------------------------
Write a script:
1. display the current system date and time, and then create the directory/tmp/lstest
2. Switch the working directory to/tmp/lstest.
3. create directories a1d, b56e, and 6 Test
4. Create an empty file XY, x2y, 732
5. list files or directories starting with a, X, or 6 in the current directory;
6. list files or directories starting with letters, followed by any number, and followed by any characters in length under the current directory;
#! /Bin/bash
#
Date
Mkdir/tmp/lstest
CD/tmp/lstest
Mkdir ALD b56e 6 Test
Touch XY x2y 732
Ls-LDH [ax6] *
Ls-LDH [[: Alpha:] [0-9] *
----------------------------------------------------------------------
Write a script to complete the following functions:
1. pass two integers to the script to calculate and display the sum, difference, product, and quotient of the two integers respectively.
#! /Bin/bash
#
Echo "$1 + $2 is $[$1 + $2]"
Echo "$1-$2 is $ [$1-$2]"
Echo "$1*$2 is $[$1 * $2]"
Echo "$1/$2 is $ [$1/$2]"
-----------------------------------------------------------------------------
Write a script:
1. Switch the working directory to/var
2. Send hello to each file or subdirectory in the/var directory in sequence, for example:
(Tip: For file in/var/*; or for file in 'ls/var ';)
Hello, log
Hello, run
3. There are multiple files in the statistics/var directory and the files are displayed.
#! /Bin/bash
Let sum = 0
For file in/var/*; do
Echo "Hello, $ file"
Sum = $ [$ A + 1]
Done
Echo $ sum
Unset sum
---------------------------------------------------------------------------
Write a script:
1. Set the value of the variable file to/etc/passwd.
2. read lines 2, 4, 6, 10, 13, and 15 of the file/etc/passwd cyclically and display the content. (Note: line = 'head-2/etc/passwd | tail-1' can get 2nd rows)
3. Save these rows to the/tmp/mypasswd file.
#! /Bin/bash
#
File =/etc/passwd
Exec 3>/tmp/mypasswd
For N in 2 4 6 10 13 15; do
Line = 'head-$ N $ file | tail-1'
Echo $ line
Echo $ line> & 1
Done
Exec 3> &-
Unset file line
---------------------------------------------------------------------------------
Write a script:
1. Set the value of the variable file to/etc/passwd.
2. Send hello to each user in/etc/passwd in sequence, for example, (note: lines = 'wc-L/etc/passwd | cut-d ""-f1 ')
Hello, Root.
3. Count the total number of users
#! /Bin/bash
# Hello everyone
File =/etc/passwd
Let line = 0
Line = 'wc-L/etc/passwd | cut-d ""-f1'
For u in 'seq 1 $ line'; do
Username = 'head-$ U $ file | tail-1 | cut-D:-f1'
UUID = 'head-$ U $ file | tail-1 | cut-D:-F3'
Echo "Hello $ username"
Echo "Your uid is $ UUID"
Done
Echo users $ line
Unset line u n username UUID
----------------------------------------------------------------------------------
Write a script:
1. Set the value of the variable file to/etc/passwd.
2. Send hello to each user in/etc/passwd in sequence and specify the ID of the other user, as shown in the following figure: lines = 'wc-L/etc/passwd | cut-d ""-f1 ')
Hello, root, your uid is 0.
3. Count the total number of users
#! /Bin/bash
#
LFS = $ '\ N'
Let a = 0
For line in 'cat/etc/passwd'; do
Username = 'echo $ Line | cut-D:-f1'
Id = 'echo $ Line | cut-D:-F3'
Echo "Hello, $ username ID $ id"
A = $ [$ A + 1]
Done
Echo "$ A users"
Unset LFS sum line username ID
---------------------------------------------------------------------
Write a script:
1. Add 10 users from user1 to user10, but the user must not be added;
#! /Bin/bash
#
For I in {1 .. 10}; do
Grep user $ I/etc/passwd &>/dev/null | useradd user $ I
Done
Unset I
----------------------------------------------------------------------
Write a script:
1. Run the ping command to test whether all hosts between 192.168.0.151 and 192.168.0.254 are online,
If it is online, "IP is up." is displayed ."
If it is not online, "IP is down." is displayed ."
# I/bin/bash
#
For I in {151,254}; do
Ping-C1-W1 192.168.0. $ I &>/dev/null & Echo "IP is up" | echo "IP is down"
Done