Interview Prep/Linux/Scheduling, automation and scripting

A cron job runs a script that calls `rsync` to another host over SSH, but in cron it hangs forever. What's going on and how do you design it properly?

IntermediateScenarioScheduling, automation and scripting
Answer

Situation read → No SSH agent and no TTY in cron; SSH is waiting for a password or host key confirmation.

What I'd do →

  1. Use a dedicated key without a passphrase, restricted on the remote side (command=, from=).
  2. Pre-populate known_hosts.
  3. Make SSH fail fast:
rsync -a -e "ssh -i /home/sync/.ssh/id_ed25519 -o BatchMode=yes -o ConnectTimeout=10" /data/ sync@backup:/data/
  1. Wrap with timeout 2h so it can't hang forever.

Why → BatchMode=yes turns a hidden prompt into an immediate error you can see in logs.

Interview tip → Mention timeout as a general safety net for every scheduled job.

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting