How to run the sftp command with a password from Bash script?

后端 未结 9 706
礼貌的吻别
礼貌的吻别 2020-11-22 11:55

I need to transfer a log file to a remote host using sftp from a Linux host. I have been provided credentials for the same from my operations group. However, since I don\'t

9条回答
  •  长情又很酷
    2020-11-22 12:47

    You can use lftp interactively in a shell script so the password not saved in .bash_history or similar by doing the following:

    vi test_script.sh
    

    Add the following to your file:

    #!/bin/sh
    HOST=
    USER=
    PASSWD=
    
    cd 
    
    lftp<

    And write/quit the vi editor after you edit the host, user, pass, and directory for your put file typing :wq .Then make your script executable chmod +x test_script.sh and execute it ./test_script.sh.

提交回复
热议问题