Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make a script execute regularly

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

I. Planning tasks

1. Non-root users create scheduled tasks

Crontab-u bin-e

Crondtab-u bin-l / / View method

Ls / var/spool/cron/ all scheduled tasks are stored in directory

two。 Advanced crontab, tampering with a system-level scheduled task

Ls / etc/cron / / double press the tab key to view

Cron.d/ # scheduled tasks at the system level

The cron.daily/ # system performs scheduled tasks every day

The cron.hourly/ # system performs scheduled tasks every hour

The cron.monthly/ # system performs scheduled tasks every month

The cron.weekly/ # system performs scheduled tasks every week

Find / etc/cron* / / View scheduled tasks that can be added at the system level

Case: add a system-level * program

Vim / etc/cron.daily/tmpwatch / / add at the end of the script that periodically deletes temporary files in the / tmp directory

Echo aaa

Troubleshooting method: use md5sum to verify the integrity of the file. The MD5 is different before and after script modification.

Syntax: md5sum fil

Generate MD5 values for all files under / etc/cron*

Find / etc/cron*-type f-exec md5sum {}\; > / usr/share/file_md5.v1 / / generate ahead of time, if forgotten, operate from the new machine

Find / etc/cron*-type f-exec md5sum {}\; > / usr/share/file_md5.v2 / / if you suspect a problem, generate

Diff / tmp/file_md5.v1 / tmp/file_md5.v2 / / comparison of the last two

Note: 1 * / / is the first minute of every hour!

2. Boot and start

1. / etc/rc.local / / add a * * script to the boot script

Troubleshooting method: filter out blank lines when displayed

Grep-v ^ $/ etc/rc.local / / ^ $# begins with a blank and ends with an empty line. -v # indicates inversion, showing

Note: be sure to cat, do not use vim, because some * * will deliberately add a lot of blank lines to the rc.local and add a script in the middle or at the end

two。 Use the boot server script to load * programs, such as httpd (apache web server startup script), and even more powerful * write a boot startup program by yourself.

The script files in the ls / etc/init.d/ directory are all script files that can be booted and started.

Troubleshooting method:

Method 1: compare the good configuration files of other servers and use the MD5 value to do the comparison

Method 2: view the files that were generated or modified on the same day

Find / etc/init.d/-mtime-1 / / View files that have been modified from the previous day to the present

Third, the system command is replaced by someone, set a trigger event

Troubleshooting method: use rpm to check the integrity of files

Syntax: name of rpm-V package / / use rpm to check file integrity

Absolute path of the rpm-Vf command / / use rpm to check the integrity of the command

Rpm-Va / / check all rpm installed software packages and see if the generation commands or files have been changed

Description:

S file Size size is inconsistent

M Mode model is inconsistent (including licenses and file types)

5 MD5 sum checksum inconsistency

D Device master-slave device number mismatch

L readLink path mismatch

U User genus and master are inconsistent

G Group belongs to different groups

T mTime modification time is inconsistent

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.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report