Linux scheduled task crontab is not effective
After using the command "service crond status" to check, the following information appears: "Cron: pam_unix (cron:session): session opened/closed for user root by (uid=0)".
This is because cron can run at a configured interval. When cron performs this operation, it usually runs as the root user, creating a session for the specified user.
To make the necessary modifications:
-
Go to the directory /etc/pam.d.
-
Open the file named common-session-noninteractive.
-
Search for the content "session required pam_unix.so" (usually at the end).
-
Above this line, add the following:
session [success=1 default=ignore] pam_succeed_if.so service in cron quiet use_uid
-
Save and exit the file.
-
Restart the crond service (or cron for Ubuntu).
Now you can give it a try, and it should work.