PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 15, 2022

[FIXED] How to make correct use of sshpass along with password and different port?

 July 15, 2022     continuous-deployment, jenkins, jenkins-plugins, web-deployment     No comments   

Issue

I am building a job in jenkins in which i need to copy the folders and file from jenkins server to another server. The server has port 802 and password= "PASSWORD" how to copy folder to another server?

sshpass -p'PASSWORD'scp -P 802 $SSH_OPTS  -r $WORKSPACE/target/abc.war root@2xx.xx.xxx.xx:/root/war/

Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
   -f filename   Take password to use from file
   -d number     Use number as file descriptor for getting password
   -p password   Provide password as argument (security unwise)
   -e            Password is passed as env-var "SSHPASS"
   With no parameters - password will be taken from stdin

   -P prompt     Which string should sshpass search for to detect a password prompt
   -v            Be verbose about what you're doing
   -h            Show help (this screen)
   -V            Print version information
At most one of -f, -d, -p or -e should be used
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Solution

The best way to do this is using expect script, you can use the below code:

!/usr/bin/expect -f

Usage sshsudologin.expect (host) (ssh user) (ssh password)

set timeout 10

spawn scp -r "/folder_to_copy/" [lindex $argv 1]@[lindex $argv 0]:"destination_dir/"

expect "*?assword" { send "[lindex $argv 2]\r" }

expect eof



Answered By - piyush sachdeva
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing