遍历所有用户的 crontab 任务:
for user in $(cut -f1 -d: /etc/passwd); doecho "Crontab for user: $user"sudo crontab -u $user -l 2>/dev/null || echo "No crontab for user: $user"echo "-----------------------------"
done
输出:
Crontab for user: bin
No crontab for user: bin
-----------------------------
Crontab for user: daemon
No crontab for user: daemon
-----------------------------
Crontab for user: adm
No crontab for user: adm
-----------------------------
Crontab for user: lp
No crontab for user: lp
-----------------------------
Crontab for user: sync
No crontab for user: sync
-----------------------------
Crontab for user: shutdown
No crontab for user: shutdown
-----------------------------
Crontab for user: halt
No crontab for user: halt
-----------------------------
Crontab for user: mail
No crontab for user: mail
-----------------------------
Crontab for user: operator
No crontab for user: operator
-----------------------------
Crontab for user: games
No crontab for user: games
-----------------------------
Crontab for user: ftp
No crontab for user: ftp
-----------------------------
Crontab for user: nobody
No crontab for user: nobody
这个脚本会列出每个用户的 crontab 内容(如果有的话)。
用户级别:sudo crontab -u 用户名 -l
系统级别:cat /etc/crontab
查看所有用户的任务:sudo cat /var/spool/cron/crontabs/*