Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

unix - 如何列出所有用户的所有cron作业?(How do I list all cron jobs for all users?)

Is there a command or an existing script that will let me view all of a *NIX system's scheduled cron jobs at once?

(是否有命令或现有脚本可以让我一次查看所有* NIX系统的预定cron作业?)

I'd like it to include all of the user crontabs, as well as /etc/crontab , and whatever's in /etc/cron.d .

(我希望它包含所有用户crontabs,以及/etc/crontab ,以及/etc/cron.d任何内容。)

It would also be nice to see the specific commands run by run-parts in /etc/crontab .

(看到/etc/crontab run-parts运行的特定命令也很好。)

Ideally, I'd like the output in a nice column form and ordered in some meaningful way.

(理想情况下,我希望以一种漂亮的列形式输出并以一些有意义的方式排序。)

I could then merge these listings from multiple servers to view the overall "schedule of events."

(然后,我可以合并来自多个服务器的这些列表,以查看整个“事件安排”。)

I was about to write such a script myself, but if someone's already gone to the trouble...

(我本来就要写这样一个剧本,但是如果有人已经麻烦了......)

  ask by yukondude translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You would have to run this as root, but:

(你必须以root身份运行它,但是:)

for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done

will loop over each user name listing out their crontab.

(将遍历列出其crontab的每个用户名。)

The crontabs are owned by the respective users so you won't be able to see another user's crontab w/o being them or root.

(crontabs由各自的用户拥有,因此您将无法看到另一个用户的crontab,而不是他们或root用户。)


Edit if you want to know which user a crontab belongs to, use echo $user

(编辑如果您想知道crontab属于哪个用户,请使用echo $user)

for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...