sshpass: command not found error

2020-03-13 08:43发布

I am trying to automate the file transfer or FTP from one server to the other.

#!/bin/bash
### In this model, the same filename is processed on each run.
### A timestamp is added to the result file and data file is copied to the archive or error folder with a timestamp after processing.

# Set current directory
cd `dirname "$0"`

# Set the environment variables
. ./Environment.sh $0

#######################################################################################################
# 
#######################################################################################################


FILE=/hcm/Inbound/file.csv

sshpass -p 'xyz' sftp -oBatchMode=no -b - -oStrictHostKeyChecking=no zys@192.abc.taleo.net <<_EOF_

cd /upload/

put $FILE

_EOF_

# Exit
exit $?

When I am executing this shell script I am getting the following error in putty :

 -bash: sshpass: command not found

I tried using the ssh passwordless method by ssh-keygen -t dsa and other steps but I cannot access putty of the second server due to which I am not being able to execute the next steps.

Kindly help

4条回答
迷人小祖宗
2楼-- · 2020-03-13 09:01

you will need to install sshpass on the client server you are running your code in which is a tool that is not installed by default on most Linux distro

if you are in Ubuntu use this command

apt-get install sshpass

on centOS/redhat use this install epel

wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.noarch.rpm

install sshpass

yum --enablerepo=epel -y install sshpass

Thanks

查看更多
啃猪蹄的小仙女
3楼-- · 2020-03-13 09:11

One solution I got for CentOS 7 :

  1. Click on the link

And rpm will be downloaded.

  1. Transfer this rpm to your linux system (you can use filezilla etc.).
  2. Install the Rpm using: yum install <rpm file name>.

DONE

查看更多
欢心
4楼-- · 2020-03-13 09:13

NO!!!! Don't install sshpass. It is the wrong tool for your job.

It was not written for your use case, and if you do use it, your script will be considerably less secure than it can be. I should know what I'm talking about. I wrote it.

Instead, run your server with debugging info and figure out why you failed to set up key based authentication. It is preferable to using sshpass in every possible way.

查看更多
成全新的幸福
5楼-- · 2020-03-13 09:21

Take a look at this post How to put sshpass command inside a bash script?

If you would like to script sshpass's ssh

export SSHPASS=password
sshpass -e ssh -oBatchMode=no user@host
查看更多
登录 后发表回答