Skip to content
linscpSecure file transfer for Linux and Windows
GitHub

Automation & scripting

Scheduling

Run linscp-cli jobs on a timetable with cron or a systemd timer on Linux, or Task Scheduler on Windows.

Reviewed

A scheduled job runs without you, often as a different user and with a bare environment. Prepare the script for that first, then pick a scheduler.

  • Run it by hand first, as the same user the scheduler will use. Fix every prompt it shows: an unknown host key or a missing password will make the scheduled run fail.
  • Mind whose configuration it reads. Stored sites and accepted host keys live in that user’s ~/.config/linscp/WinSCP.ini. A job run as root or as a service account does not see yours. Either set the site up as that user, or make the script self-contained with a URL and -hostkey.
  • No agent, no desktop. Jobs started by cron or systemd have no $SSH_AUTH_SOCK and no keyring. Use a key file or a password file, as described in sessions and credentials.
  • Always add /nointeractiveinput and a /log=, so a run that goes wrong stops and leaves a trace.

The examples call the wrapper ~/jobs/upload.sh from your first automated transfer.

Edit your crontab with crontab -e and add a line. This one runs the job at 02:30 every night:

30 2 * * * /usr/bin/flock -n /home/alice/jobs/upload.lock /home/alice/jobs/upload.sh >>/home/alice/jobs/cron.log 2>&1

flock -n skips a run while the previous one is still going. cron mails or discards the output depending on the system, so redirect it to a file you will look at. cron’s PATH is short; call programs by full path when in doubt (/usr/bin/linscp-cli).

The exit code of linscp-cli becomes the job’s result, so systemctl --user status upload.service shows a failed run as failed.

Create the task from an elevated or normal Command Prompt, depending on the account it runs as:

Terminal window
schtasks /create /tn "linscp upload" /sc daily /st 02:30 ^
/tr "\"C:\Program Files\linscp\linscp-cli.exe\" /nointeractiveinput /script=C:\Users\alice\jobs\upload.txt /log=C:\Users\alice\jobs\upload.log"

Or open Task Scheduler, choose Create Task, and on the Actions tab enter linscp-cli.exe as the program, the switches as arguments, and the job folder as Start in so relative paths in the script resolve.

Pick Run whether user is logged on or not for unattended runs. The task then runs in a separate session under that account, so the host key must be stored for that account or passed with -hostkey.

A schedule can break quietly when a password expires or a host key changes. Have the wrapper report failures: send mail from the shell when the exit code is not 0, or let your monitoring watch the log file’s age. See exit codes and error handling.