2

I am running an rsync script to copy files from a pi to local folder, the script works as intended when run manually but fails with:

: Host key verification failed.
: rsync error: unexplained error (code 255) at rsync.c(703) [Receiver=3.2.3]

When run by a service file, would appreciate any help on where I am going wrong.

script:

#!/bin/bash

experimentNum=$(sshpass -p 'pass' ssh user@IP "cat /source/source.txt")

mkdir -p /dest/$experimentNum

sshpass -p 'pass' rsync -zaP user@IP:/source/ /dest

sshpass -p 'pass' ssh user@IP sudo find /source/ -mtime +14 -daystart -delete

Service:

[Unit]
Description=backup
StartLimitIntervalSec=0

[Service]
Type=oneshot
ExecStart=/usr/bin/bash /absolute-path/drive_backup.sh
Restart=on-failure
RestartSec=5

1 Answers1

2

Right so fairly simple fix and something that I overlooked was running the service for the user (with User=user under the [service] sub-heading) that created the ssh key not remembering that they are specific to a user!

[Unit]
Description=backup
StartLimitIntervalSec=0

[Service]
Type=oneshot
ExecStart=/usr/bin/bash /absolute-path/drive_backup.sh
Restart=on-failure
RestartSec=5
User=user
earthmeLon
  • 11,042
  • 1
  • 36
  • 60