Linux Fundamentals 10

Source: Internet
Author: User

Recurring Scheduled Tasks
crontab command
System services:/etc/init.d/crond (Crond must be started to take effect)
User plan:/var/spool/cron/user name
Default scheduled task
Global configuration:/etc/crontab
System Plan:/etc/cron.hourly/* (to be performed per hour)
/etc/cron.daily/* (to be performed daily)
/etc/cron.weekly/* (per week)
/etc/cron.monthly/* (to be executed monthly)
[[email protected] Desktop]# rpm-qa | grep cron (see if this service is installed)
Crontabs-1.10-33.el6.noarch
cronie-anacron-1.4.4-15.el6.x86_64
cronie-1.4.4-15.el6.x86_64
[[Email  protected] Desktop]#/etc/init.d/crond status (see if this service is running)
Crond (PID 2715) is running ...
[[email protected] Desktop]# chkconfig crond--list
Crond 0: Off 1: Off 2: Enable 3: Enable 4: Enable 5: Enable 6: Turn off
[[email  Protected] Desktop]# ls/etc/cron.hourly/(script to execute every hour)
0anacron mcelog.cron
[[email protected] Desktop]# ls/etc/ cron.daily/(script to be executed every day)
Cups logrotate makewhatis.cron mlocate.cron prelink readahead.cron rhsmd tmpwatch
[[Email  protected] Desktop]# ls/etc/cron.weekly/(script to be executed every week)
[[email protected] Desktop]# ls/etc/cron.monthly/ (script to be executed monthly)
Readahead-monthly.cron

[[Email protected] Desktop]# Vim/etc/crontab (Master profile)
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
home=/

# for details see Mans 4 Crontabs

# Example of Job definition:
#.----------------Minute (0-59)
# |.-------------Hour (0-23)
# | |.----------DAY of Month (1-31)
# | | |.-------month (1-12) OR jan,feb,mar,apr ...
# | | | |.----DAY of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * * user-name command to be executed
*: Any time within the matching range
,: Indicates multiple discontinuous points in time
-: Indicates a continuous time range
/n: Specify the time frequency, per n ...
Record format
Execution cycle, executable statement
Minute hour date Month Week executable statement
Execution Cycle Setup Description
Number of minutes from 0 to 59
Number of hours from 0 to 23
Number of dates from 1 to 31
Number of months from 1 to 12
Integer between week 0-7, 0 or 7 for Sunday

To perform a periodic display column:
0 17 * * 1-5 weeks to Friday daily 17:00
30 8 * * 1,3,5 every Monday, Wednesday, Friday 8:30
0 8-18/2 * * * 8 to 18 No. 2 hours
0 0 */3 * * 0 points per three days

crontab command format:
Edit Cron Scheduled Tasks
Format: crontab-e [u user name]
View Cron Scheduled Tasks
Format: crontab-l [u user name]
Delete Crontab Scheduled Tasks
Format: crontab-r [u user name]

[[Email protected] Desktop]# crontab-e (edit scheduled Task)
7 * * */etc/init.d/sshd start (open every 7:30)
* * * */etc/init.d/sshd Stop (open every 23:30)
[[Email protected] Desktop]# crontab-l (view scheduled Tasks)
7 * * */ETC/INIT.D/SSHD start
* * * */etc/init.d/sshd stop
[[Email protected] Desktop]# crontab-r (Delete scheduled task, this is not good, can not delete a single)

Authorization for Scheduled Tasks
Cron Task Control
/etc/cron.allow/etc/cron.deny
[[Email protected] Desktop]# Ls/etc/cron.allow/etc/cron.deny
LS: Unable to access/etc/cron.allow: No file or directory
/etc/cron.deny
Allows the specified user if the Allow file exists
Otherwise, the Deny file is checked, except for the rest of the specified user allowed
If none of the two files exist, only root is allowed

Scheduled task interruption and remediation
Anacron Delay Remediation
Task cycle: Check every hour, tasks within the last X days
Perform missed task actions by Crond Service Dispatch check
[Email protected] Desktop]# rpm-ql Cronie-anacron | grep etc
/etc/anacrontab (Global configuration)
/etc/cron.hourly/0anacron (script for checking tasks)
[[Email protected] Desktop]# tail-3/etc/anacrontab (Anacreon Master profile)
15cron.dailynice run-parts/etc/cron.daily
725cron.weeklynice run-parts/etc/cron.weekly
@monthly 45cron.monthlynice run-parts/etc/cron.monthly

——————————————————————————————————————————————————————
Process Management
Program: Save the executable file in the disk, is the static saved code
Process: Program instructions run in CPU and memory, are dynamic execution code, process can create one or more child processes (parent/child process)
View Process Tree
Pstree command
Format: pstree [options] [PID or user name]
Common Command Options
-A: Displays the full command line
-U: Lists the user names that each process belongs to
-P: List the corresponding PID number
[Email protected] ~]# Pstree-aup xx01
bash,5905
└─vim,5930
viewing process snapshots
PS command
Format: PS [options]
Common Command Options
-A: Displays all processes under the current terminal
-U: Use user-oriented format to output information
-X: Displays the current user's process under the terminal
-E: Displays all processes within the system
-L: Output information using long format
-F: Output information in the most complete format
[[Email protected] ~]# PS aux (High level of detail, listing all running processes)
USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND
Root 1 0.0 0.1 19364 1540? Ss 17:16 0:03/sbin/init
Root 2 0.0 0.0 0 0? S 17:16 0:00 [Kthreadd]
..... ....
[[email protected] ~]# ps-elf (Low level of detail, listing all running processes)
F S UID PID PPID C PRI NI ADDR SZ wchan stime TTY time CMD
4 S root 1 0 0 0-4841 poll_s 17:16? 00:00:03/sbin/init
1 S root 2 0 0 0-0 kthrea 17:16? 00:00:00 [Kthreadd]
..... ....
Stat column, which reflects the state of the process
-R: Running
-S: In hibernation, can be awakened when needed
-D: Non-disruptive hibernation, usually waiting for I/O (read and write)
-T: Stop state
-Z: Zombie status, the program has been terminated, but the occupied memory is not released

Process Dynamic Ranking
Top Interactive tools
Format: Top [-D refresh seconds] [-u user name] (default to 3 seconds for refresh seconds)
[[Email Protected]ong desktop]# top-d5 (Refresh once every 5 seconds)

top-22:40:38 up 5:23, 2 users, load average:0.02, 0.02, 0.00
tasks:181 Total, 1 running, sleeping, 0 stopped, 0 zombie
Cpu (s): 3.6%us, 0.4%sy, 0.0%ni, 96.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
mem:1004768k Total, 852424k used, 152344k free, 69264k buffers
swap:5054460k Total, 0k used, 5054460k free, 365344k cached

Retrieving process information
Pgrep command
Purpose: pgrep [options] Query criteria
Common Command Options
-L: Output process name, not just PID
-U: Retrieves the process for the specified user
-T: Retrieving the process for the specified terminal
[[Email protected] Desktop]# pgrep-l net
Netns
2498 xinetd

Pre-and post-process scheduling
Foreground start: Enter a normal command line that occupies the current terminal during operation
Background startup: Add & Symbols at the end of the command line, without occupying the current terminal during operation
CTRL + Z key combination: Suspend current process (pause and move to background)
Jobs command: View background Task List
FG Command: Restore background tasks to foreground run
BG command: Activate a task that is suspended from the background
(The default is the last 1 tasks when the FG,BG command does not specify a sequence number)

Terminating a process
CTRL + C key combination
Kill,killall command
Kill PID number, Killall process name
Line Selection-9 means forced termination
Pkill command: Kills a process that matches a specified condition, with a usage similar to Pgrep
[[Email protected] Desktop]# Killall sleep
[1]-has terminated sleep 900
[2]+ has terminated sleep 900

————————————————————————————————————————
Linux startup process
Load BIOS, check hardware information
Read and execute the boot Loader of the MBR in the first boot device
Run GRUB boot Load kernel
Kernel Boot/sbin/init Program
Init system Initialization
Determining the default Run level
Trigger Runleve event, run/ETC/RC.D/RC
Final execution/etc/rc.local
Load terminal or X-windows interface

————————————————————————————————————

Linux Fundamentals 10

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.