How to use scp and ssh command in a same script? First I have to copy one file from my local server to remote. Then from local server itself, I have to check the size of the copied file.

  • What's the rationale for not being able to use SSH keys? Your Q really makes no sense, given you're using SCP and SSH. – slm Feb 7 '14 at 8:18
  • I'd recommend using rsync to handle the copy and checking with ssh as its backend, then set up a passwordless public/private authentication key for rsync to use. Keep the private key in a directory accessible only to the userid running the rsync script. Done. – Shadur Feb 7 '14 at 9:25

I would use public/private key to automate the conection without the need of using a password.

  • more coffee OK, but more glasses will probably reduce your sight instead of enhanceing it @Anthon – Kiwy Feb 7 '14 at 8:36
  • 1
    @kiwi even if going from 0 to 1? – Anthon Feb 7 '14 at 8:38

Yes, you need keys. Step 1. generate them At terminal (assuming CentOs/RHEL or similar): ssh-keygen (quick-shortcut - YES - to all)

Step 2. Put your public keys onto that remote server. Actually save yourself trouble and run the following: ssh-copy-id @

Done. You have your keys on the remote system now. Now you can test logging in without the password (password-free-access)

Test with: ssh @ If you get to login without any prompt for password. super.

Then you can just copy things over and do all those file size checks now : scp file.ext @:/some/location ; ssh @ "du /some/location/file.ext"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.