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

Detailed explanation of scheduled tasks for ordinary users in linux

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Preface

Ordinary user-defined crontab timing tasks: for example, oracle users define a scheduled task: print the current directory every minute

[oracle@node2] $crontab-e

* / 1 * / bin/ls-al > / tmp/ls.log

How to determine whether a scheduled task has been carried out? First of all, the crond service should be running.

[oracle@node2 ~] $service crond statusRedirecting to / bin/systemctl status crond.service ● crond.service-Command SchedulerLoaded: loaded (/ usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2018-07-15 08:27:38 EDT; 2min 43s agoMain PID: 6189 (crond) CGroup: / system.slice/crond.service └─ 6189 / usr/sbin/crond-n [oracle@node2] $

1. Use the mail command under the root user

[root@node2] # mailHeirloom Mail version 12.5 7-5-10. Type? For help. "/ var/spool/mail/root": 801 messages 9 new 94 unreadN795 (Cron Daemon) Sun Jul 15 08:25 35Universe 932 "Cron / bin/ls" N796 (Cron Daemon) Sun Jul 15 08:26 35Universe 932 "Cron / bin/ls" N797 (Cron Daemon) Sun Jul 15 08:27 35lash 932 "Cron / bin/ls" N798 (Cron Daemon) Sun Jul 15 08:28 35MB 932 "Cron / bin/ls" N799 (Cron Daemon) Sun Jul 15 08:29 35 / 932 "Cron / bin/ls" N800 (Cron Daemon) Sun Jul 15 08:30 35pm 932 "Cron / bin/ls" & file "/ var/spool/mail/root": 801 messages 9 new 94 unread& h > N793 (Cron Daemon) Sun Jul 15 08:23 35x932 "Cron / bin/ls" N794 (Cron Daemon) Sun Jul 15 08:24 35pm 932 "Cron / bin/ls" N795 (Cron Daemon) Sun Jul 15 08:25 35pm 932 "Cron / bin/ls" N796 (Cron) Daemon) Sun Jul 15 08:26 35amp 932 "Cron / bin/ls" N797 (Cron Daemon) Sun Jul 15 08:27 35MB 932 "Cron / bin/ls" N798 (Cron Daemon) Sun Jul 15 08:28 35max 932 "Cron / bin/ls" N799 (Cron Daemon) Sun Jul 15 08:29 35pm 932 "Cron / bin/ls" N800 (Cron Daemon) Sun Jul 15 08:30 3532 "Cron / bin/ls" & 800Message 800:From root@node2.matengbing.com Sun Jul 15 08:30:01 2018Return-Path: X-Original-To: rootDelivered-To: root@node2.matengbing.comFrom: "(Cron Daemon)" To: root@node2.matengbing.comSubject: Cron / bin/lsContent-Type: text/plain Charset=UTF-8Auto-Submitted: auto-generatedPrecedence: bulkX-Cron-Env: X-Cron-Env: Date: Sun, 15 Jul 2018 08:30:01-0400 (EDT) Status: r\ anaconda-ks.cfgDesktopDocumentsDownloadsinitial-setup-ks.cfgMusicPicturesPublicTemplatesVideos

In the mial interactive environment, use the file command to display the total number of current messages and other information to view the details of the mail via head to view the most recent mail input number

two。 View the log: tail-n 10 / var/log/cron

[root@node2] # tail-n 10 / var/log/cronJul 15 08:31:01 node2 CROND [6297]: (root) CMD (/ bin/ls) Jul 15 08:31:01 node2 CROND [6298]: (oracle) CMD (/ bin/ls-al > / tmp/ls.log) Jul 15 08:32:01 node2 CROND [6321]: (oracle) CMD (/ bin/ls-al > / tmp/ls.log) Jul 15 08:32:01 node2 CROND [6322]: (root) CMD (/ bin/ls) Jul 15 08:33:02 node2 CROND [6342]: (root) CMD (/ bin/ls) Jul 15 08:33:02 node2 CROND [6343]: (oracle) CMD (/ bin/ls-al > / tmp/ls.log) Jul 15 08:34:01 node2 CROND [6362]: (root) CMD (/ bin/ls) Jul 15 08:34:01 node2 CROND [6363]: (oracle) CMD (/ bin/ls-al > / tmp/) Ls.log) Jul 15 08:35:01 node2 CROND [6382]: (oracle) CMD (/ bin/ls-al > / tmp/ls.log) Jul 15 08:35:01 node2 CROND [6383]: (root) CMD (/ bin/ls) [root@node2 ~] #

The execution of scheduled tasks of all users is recorded in the log file

3. Use mail to view under ordinary users

(the user who performs the scheduled task should be specified in the scheduled task, otherwise even the scheduled task defined under the oracle user may not receive mail.)

[oracle@node2] $crontab-al 1 * oracle / bin/ls-al > / tmp/ls.log [oracle@node2 ~] $[oracle@node2 ~] $mailHeirloom Mail version 12.5 7-5-10. Type? For help. "/ var/spool/mail/oracle": 6 messages 1 unread1 (Cron Daemon) Mon Mar 5 14:10 52 Cron Daemon 2476 "Cron ls-al" 2 (Cron Daemon) Sun Jul 15 06:10 572777 "Cron / bin/ls-al" 3 (Cron Daemon) Sun Jul 15 06:11 57max 2777 "Cron / bin/ls-al" 4 (Cron Daemon) Sun Jul 15 06:12 57max 2778 "Cron / bin/ls-al" 5 (Cron Daemon) Sun Jul 15 06:13 57 Cron 2778 "Cron / bin/ls-al" > U 6 (Cron Daemon) Sun Jul 15 08:38 26 Charger 929 "Cron oracle / bin/ls-al > / tmp/ls.log" &

The / var/log/cron file cannot be viewed directly under ordinary users

[oracle@node2 ~] $tail-n 10 / var/log/crontail: cannot open'/ var/log/cron' for reading: Permission deniedYou have new mail in / var/spool/mail/oracle [oracle@node2 ~] $

There is also a way to write scheduled tasks in the / etc/crontab file, but writing to execute in that file in centos7 will report an error.

[oracle@node2] $cat / etc/crontabSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root# For details see man 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 [oracle@node2] $

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support.

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

Servers

Wechat

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

12
Report