0

I'm new - Very new to UNIX and have been dropped in the deep end.

I an trying to automate the transfer of files from a remote SFTP server back to our SFTP server, I need to login using an SSH private.

I have managed to muddle my way through this with a full hands on approach but when I try to do it from a cron job I get the following error straight away:

/bin/sh: 1: /home/administrator/from_cepsa_to_SFTP.sh: Permission denied

I'm not sure where this comes from as it isn't in my script as below:

sftp -i /home/administrator/key/key.txt [email protected]
sftp> cd /out
sftp> lcd /home/administrator/key
sftp> get key2.txt
sftp> cd /out/processed
sftp> put key2.txt
sftp> cd /out
sftp> rm key2.txt
Removing /out/key2.txt
sftp> exit

Now I might be being hopeful that I can just take what I used in the manual entries and turn it into a script but I would be really grateful for any pointers/advice and support please?

What I have noticed from a previous script to do similar is it calls:

sshpass -e sftp -oBatchMode=no  -oport=61140 -oHostKeyAlgorithms=+ssh-dss -b - [email protected] << !

I know I am not using 'sshpass' but I guess I'm missing something to call the SSH SFTP transfer

thank you :)

2
  • It look like the account that runs the crop job does not have execute permissions to your script. I do not think your question has anything to do with SFTP. I believe you would get the same error, even if your script did simple echo something - Though once you resolve this - Your script does not even look like a script, it cannot work, even if you run it manually. Jul 17, 2019 at 14:46
  • Thank you, you are correct I have looked at permissions and can see that as you pointed out I have not allowed the account execute permissions. In my defense about the script not being a script, it's the the first time I have done anything in this detail in UNIX hence admitting straight away that I have just put what i manually typed and thought it 'might' have worked.
    – Paul
    Jul 17, 2019 at 15:32

1 Answer 1

0

Your crontab-entry should look like:

0 1 * * * /bin/bash /home/administrator/from_cepsa_to_SFTP.sh

Alternatively, you could chmod +x /home/administrator/from_cepsa_to_SFTP.sh.

I'm not sure on what your script looks like, but it should probably be something like:

#!/bin/bash
sftp  -i /home/administrator/key/key.txt [email protected] <<EOF
cd /out
lcd /home/administrator/key
get key2.txt
cd /out/processed
put key2.txt
cd /out
rm key2.txt
exit
EOF
3
  • Hi, with the suggested edit, would I not get a prompt to enter a password during the handshake?
    – Paul
    Jul 19, 2019 at 9:22
  • ehr.. sorry, my mistake. Added the -i option. Point is that the prompts should not be there and the here-document (<<EOF ... EOF) Jul 19, 2019 at 18:53
  • I'm now getting the following: /bin/sh: 1: /home/administrator/auto.sh: Permission denied Changed permissions as yes I did it again... /bin/sh: 1: /home/administrator/auto.sh: not found
    – Paul
    Jul 22, 2019 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .