Signal Capture and scheduling tasks

Source: Internet
Author: User

View native Hardware Device information

1.cat/proc/cpuinfo

2.lsusb

3. Lspci

4 Hal-device

Stty–f/dev/console size to take file

script Programming Knowledge points :

    1. the length of the character in the variable:${#VARNAME}

    2. Variable assignment, etc.

    3. ${parameter:-word}; if parameter is empty or undefined, the variable is expanded to Word, Otherwise, the value is expanded to parameter .

[Email protected] ~]# a=3

[[email protected] ~]# echo ${a:-30}

3

[[email protected] ~]# echo ${b:-30}

30

    1. ${parameter:+word}; if parameter is empty or undefined, do nothing; otherwise, expand to "word" value

    2. ${parameter:=word}; if parameter is empty or undefined, the variable is expanded to word, and the expanded value is given to parameter

    3. ${parameter:offset}

    4. ${PARAMETER:OFFSET:LENGT}: take a substring, start with the last character at offset and take a lengt long string

[[email protected] ~]# a= ' Hello World ' starts with the first 2 characters

[[email protected] ~]# echo ${a:2:3} Skip 2 , then take the back 3 characters

Llo

/ETC/RC.D/INIT.D Service Script

Service Script Support profile:/etc/sysconfig Service script configuration file with the same name

Local var_name= defining locals

Mktemp command to create a temporary file or directory

Mktemp/tmp/file.xxx generated random values as file names

Mktemp–d Creating a temp directory

Signal:

Kill–signal PID

in the script, the signal capture can be achieved, but 9 and cannot capture

Trap Command

Trap'COMMAND' signal list

write a script capture Crtl+c Signal

#!/bin/bash

#

Trap ' echo ' Wuxiao: ' 2

While:; Do

Date

Sleep 2

Done

Use two commands in the same row;

#!/bin/bash

#

net=192.168.50

file1= ' mktemp/tmp/file.xxx '

Clearup () {

echo "Quit"

Exit 1

Rm-f $FILE

}

Trap ' Clearup ' INT

For I in {99..254};d o

If Ping-c 1-w 1 $NET. $I &>/dev/null; Then

echo "$NET. $I is Up" | Tee >> $FILE 1

Else

echo "$NET. $I is Down"

Fi

Done

~

Task Schedule:

    1. Perform a task at some point in the future

At

At time

At>command

At>ctrl+d

Specify time:

Absolute Time hh:mm DD. Mm. YY Mm/dd/yy 10:20

relative time now+ #minutes starting from now # minutes later ,

Unit:minutes,hours,days,weeks

Blur time:noon,midnight,teatime

Use Ctrl+d to exit after editing the command

Execution result of the command: sent to the user who scheduled the task in the form of a message

At-l =atq Display job list

At–d #=atrm # Remove the # command

/etc/at.allow White list

/etc/at.denv blacklist, users who uninstall this file cannot use the at

Batch

automatically selects the system to perform tasks when it is idle. Using the same way as at

    1. To perform a task periodically

Cron: Self is a service that runs uninterrupted

Anacron:cron , can be implemented to enable cron for a variety of reasons in the past, the execution of the task is not performed after the return to normal and then execute again

Cron

system cron task

/etc/crontab

minutes hours Day Month week user tasks

User cron task

/var/spool/cron/username

minutes hours Day month week task

valid value of time

minutes:0-59

Hours:0-23

days:1-31

Month:1-12

Week:0-7,0 and 7 both indicate Sunday

Time-Pass representation:

*: Corresponds to all valid values

3 * * * * 3 minutes per hour to perform a task

3 * * 7 perform a task every three minutes every Sunday

* * * * every day of the first time

* * 5 per week , 5

,: Departure point of Time:

10,40 * * * * * every hour of the ten and a half to execute once

10,40 * * * 2,5 2 and 5 per week

-: Continuous point in time:

* * 1-5 1 to 5 per week at 2 .

/#: how often in the corresponding value range

*/3 * * * * * Run every 3 minutes

Executes every two hours:

*/2 * * *

The execution results are sent to the administrator as a message

*/3 * * * */bin/cat/etc/fstab &>/dev/null Command use absolute path

Cron environment variable:cron executes all commands to the PATH environment variable specified by the

Path down to find

Path/bin:/sbin:/user/bin:/usr/sbin

The environment variables can be defined in the script when the script is set.

#!/bin/bash

Export path=

Management of User tasks:

Crontab–l View current Tasks

Crontab–e Editing Tasks

Crontab–r Remove All Tasks

Crontab–u username-e: Managing cron Tasks for their users

[Email protected]~]# crontab-u admin-e

Nocrontab for admin-using an empty one

Crontab:installing New Crontab

[[Email protected]~]# ls/var/spool/cron/

Admin

Anacron:/etc/anacrontab

[[Email protected]~]# cat/etc/anacrontab

#/etc/anacrontab:configuration file for Anacron

# Seeanacron (8) and Anacrontab (5) for details.

Shell=/bin/sh

Path=/sbin:/bin:/usr/sbin:/usr/bin

Mailto=root

# Themaximal Random Delay added to the base delay of the jobs

Random_delay=45

# Thejobs'll is started during the following hours only

Start_hours_range=3-22

#periodin days delay in minutes job-identifier command

1 5 cron.daily Nice run-parts/etc/cron.daily

7 cron.weekly Nice run-parts/etc/cron.weekly

@monthly45 cron.monthly Nice run-parts/etc/cron.monthly

The first field indicates how many days are not executed, the second field indicates how many times the boot was executed, and the third field is the comment information

The fourth word is an order.

be sure to ensure that the Crond service is running

[Email protected]~]# service Crond Status

Crond (PID 1439) is running ...

Anacron is also sure to keep the service running properly

This service can also be managed by Chkconfig


This article from "Linux operation and Maintenance" blog, declined reprint!

Signal Capture and scheduling tasks

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.