A scheduled job needs a database password. Where do you put it for cron and for systemd?
IntermediateScenarioScenarios: text processing and scheduling decisions
Answer
Situation read → Keep it out of the crontab line, the unit file (world-readable in /etc/systemd/system), the script and Git.
What I'd do →
- Cron: a file readable only by the job's user (
install -m 0600 -o jobuser), read at runtime:DB_PASS=$(< /etc/jobs/db_pass), or a tool-specific file like~/.pgpass. - systemd 247+: credentials, which are exposed only to the service:
The script reads[Service] LoadCredential=db_pass:/etc/jobs/db_pass ExecStart=/opt/jobs/report.sh"$CREDENTIALS_DIRECTORY/db_pass".LoadCredentialEncrypted=can keep it encrypted at rest with the TPM or host key. - Cloud: fetch from AWS Secrets Manager or SSM Parameter Store with the instance role at runtime.
- Never use
Environment=DB_PASS=...in a unit file;systemctl showreveals it.
Why → Each option limits who can read the secret and keeps it out of version control.
Interview tip → Mentioning LoadCredential= shows current systemd knowledge.
More on Scenarios: text processing and scheduling decisions
Users report errors in the last hour. From the Nginx access log, find which endpoints produce the most 5xx responses.BeginnerA MySQL slow log is 3 GB. You need the 10 slowest query patterns. What do you do?IntermediateTwo servers that should be identical behave differently. Compare their installed packages.BeginnerFind which pods were OOMKilled in a namespace, with their container names and restart counts.IntermediateProduce a CSV of running EC2 instances that are missing an `Owner` tag.IntermediateYou have access logs from five web servers and need one timeline sorted by time. How?Intermediate