In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Ps: a command that displays the current process status of the system
Ps an all terminal-related processes
Ps x all terminal-independent processes
Ps u displays process-related information user-centric
VSZ:
Virtual memory set, Virutal menmory Size
RSS:
Resident memory set
STAT:
R: running or runnable
S: interruptible sleep
D: uninterrupted sleep
T: stop
Z: zombie
S:session leader has child processes
+: foreground process
L: multithreaded process
N: low priority proc
Backstage. Ctrl+z sends the foreground job to the background, and the job is "stopped".
If it is not already started: COMMAND &
If you exit the current session, the job will also be terminated, because the job is related to the current terminal. If you send the job to the background, you do not expect the job to stop with the termination.
Nohup COMMAND &
How to make the job sent to the background continue to execute:
Fg [[%] Job number]: transfer the job back to the front desk to continue
Bg [[%] Job number]: let the job continue in the background
The default is the last task to enter the background
Kill% Job number: terminate the job
Check the assignment number:
Jobs
Pmap pid to view the memory footprint of a process
00007fb60640d000 4K rw--- / sbin/init
Starting address space permission
Bash script programming: the case statement of
The syntax format of the case statement:
Case expression in
Pattern1)
Suite1
Pattern2)
Suite2
...
Patternn)
Suiten
*)
Other_suite
Esac
Modes are available for each pattern in case:
A | b an or b
* match any character of any length
? Match any single character
[-] range matching
Exercise: write a script and accept this format
Script.sh {start | stop | restart | status}
1. If start, create / var/lock/subsys/script.sh, indicating that the startup is successful.
2. If the parameter is stop, delete / var/lock/subsys/script.sh, indicating that the stop is successful.
3. If restart, delete it, create it again, and display it successfully
4. If status, if the file exists, running is displayed, otherwise, stopped is displayed
#! / bin/bash
#
MyService= `basename $0`
LockFile= "/ var/lock/subsys/$myService"
[$#-lt 1] & & echo "Usage: $myService {start | stop | restart | status}" & & exit 4
Case $1 in
'start')
Touch $lockFile
Echo "Starting $myService OK"
'stop')
Rm-f $lockFile
Echo "Stopping $myService OK"
'restart')
Rm-f $lockFile
Touch $lockFile
Echo "Restarting $myService OK"
'status')
If [- f $lockFile]; then
Echo "$myService is running"
Else
Echo "$myService is stopped"
Fi
*)
Echo "Usage: $myService {start | stop | restart | status}"
Exit 3
Esac
Exercise: write a script that packages and backs up the / etc/ directory at the / backup/etc- date. Suffix
1. The following menu is displayed to the user:
Xz) xz compress
Gzip) gzip compress
Bip2) bzip2 compress
2. Use tar to package compression according to the compression tool specified by the user.
3. If the default is xz; input error, you need to re-enter it.
#! / bin/bash
#
[- d / backup] | | mkdir / backup
Cat / dev/null & & echo "No this interface..." & & exit 3
Read-p "Enter an alias:" ethAlias
Read-p "Enter IP:" ipAddr
Read-p "Mask:" netMask
Ifconfig $ethAlias $ipAddr netmask $netMask
[$debug-eq 1] & & ifconfig $ethAlias
Functions of bash script programming
Can be called: the function has a function name
Where the function appears, it is automatically replaced with the code defined by the function
Function definition
Syntax:
FuncName () {
Function body
}
Function FuncName {
Function body
}
A function has two return values:
Data returned normally:
Print statements in a function, such as echo or print
The execution result of the command in the function
Execution status return value:
Depends on the last statement executed in the function
Customization: return N
The function can accept parameters:
Parameters similar to script call position parameters can be used in the function body.
$1, $2.
$#
$*, $@
Exercise: write a script to perform the following functions
1. Display the following menu
Disk) show disk info
Mem) show memory info
Cpu) show cpuinfo
2. Display the content selected by the user
#! / bin/bash
#
ShowMenu () {
Cat > / dev/null
If [$?-eq 0]; then
Echo-e "\ 033 [32m$ipAddr\ 033 [0m"
Else
Echo-e "\ 033 [31m$ipAddr\ 033 [0m"
Fi
}
For i in `seq 0255`; do
For j in `seq 1 254`; do
Ping $I $j
Done
Done
Exercise: write a script to perform the following functions (using functions):
1. Prompt the user for an executable command
2. Get all the library files on which this command depends (using the ldd command)
3. Copy the command to the directory corresponding to / mnt/sysroot/
Explanation: suppose that if you copy the cat command and its executable path is / bin/cat, then copy / bin/cat to the / mnt/sysroot/bin/ directory. If you copy the useradd command and the executable path of useradd is / usr/sbin/useradd, copy it to the / mnt/sysroot/usr/sbin/ directory.
4. Copy each library file to the corresponding directory of / mnt/sysroot/, which requires a command
#! / bin/bash
#
Target=/mnt/sysroot
ClearCmd () {
If which $cmd & > / dev/null; then
CmdPath= `which-- skip-alias $cmd`
Else
Echo "No such command"
Return 5
Fi
}
CmdCopy () {
CmdDir= `dirname $1`
[- d ${target} ${cmdDir}] | | mkdir-p ${target} ${cmdDir}
[- f ${target} ${1}] | | cp $1 ${target} ${cmdDir}
}
LibCopy () {
For lib in `ldd $1 | grep-o "/ [^ [: space:]]\ {1,\}" `; do
LibDir= `dirname $lib`
[- d ${target} ${libDir}] | | mkdir-p ${target} ${libDir}
[- f ${target} ${lib}] | | cp $lib ${target} ${libDir}
Done
}
While true; do
Read-p "Enter a command:" cmd
If ["$cmd" = = 'quit']; then
Echo "quit"
Exit 0
Fi
ClearCmd $cmd
[$?-eq 5] & & continue
CmdCopy $cmdPath
LibCopy $cmdPath
Done
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.