Place a job in /etc/cron.d/app-maintenance.
Run the command as appuser.
Which line is appropriate?
Files under /etc/cron.d use system-crontab syntax: five time fields, the execution user, then the command.
Detailed explanation
0 3 * * * /usr/local/bin/maintain appuserIncorrect. The user is placed after the command.
Incorrect. The user is placed after the command.
0 3 * * * appuser /usr/local/bin/maintainCorrect. It uses five time fields, appuser, and then the command.
Correct. It uses five time fields, appuser, and then the command.
appuser 0 3 * * * /usr/local/bin/maintainIncorrect. The user is placed before the time fields.
Incorrect. The user is placed before the time fields.
0 3 appuser * * * /usr/local/bin/maintainIncorrect. appuser is incorrectly placed in the day field.
Incorrect. appuser is incorrectly placed in the day field.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s\n' '0 3 * * * appuser /usr/local/bin/maintain' | awk '{print "user="$6, "command="$7}'Expected result
user=appuser command=/usr/local/bin/maintainKey points
- /etc/cron.d uses system syntax
- Sixth field is user
- Command follows user
Notes
- Environment: awk / 合成cron.d行
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.