- I want to automate downloading a file via SFTP
- I set up an SFTP server and a keying mechanism
- I have created a simple bash script - script.sh
- I added an entry in cron for the script
The script, script.sh:
#!/bin/bash sftp user@server:/home/user/file.txt exit 0
Executing the script manually works fine (text file is saved in home directory), but adding script.sh (with proper permissions) to
crontab does nothing.
The crontab entry:
* * * * * /home/user/script.sh
For authentication I used
ssh-keygen to create a set of keys (private, public) and set up cross authentication to the SFTP server.
For script automation I used
keychain for password-less authentication.
Currently, I have a script called script.sh located in the "user" home directory (
When run by
root manually, the script gets the file from the SFTP server, and places it in
It does not perform this action when run from a
cron job. In
sftp command gets an error.
Working on it
- Changing the HOME variable on
/etc/crontabdid not solve the issue
- Stating full paths in script.sh did not solve the issue
- Stating PATH variable in script.sh did not solve the issue
- I catched the error from the
sftpcommand - it's 255
executing the script manually (
./script.sh) still works flawlessly though...