The use of SCP remote transfer files under Linux, using expect technology, support the automatic input password

Source: Internet
Author: User
Tags chmod

1. Edit copycgi.sh, the main user to filter the files to be transmitted, as follows:

#!/bin/bash
Path= "./"
If [$#-eq 1]; Then
Path=$1
if [!-d $path]; Then
echo "Please input valid dir."
Exit
Fi
Fi

Ls-al ${path}/*.cgi|while Read Line
Todo
Filename= ' echo $line | awk ' {print $} '
#!echo "Start Send" $filename
./expect_scp_one.sh $filename
echo "Send ${filename} Finish"
Done

2. Edit the expect_scp_one.sh file, mainly used to transfer the specified file to the specified machine, the contents are as follows

#!/usr/bin/expect-f
Set passwd LogView
Set Src_path [lindex $argv 0]
Set Dst_path "logview@172.25.38.13:/usr/local/www.aaa.com/app/mpay/"

Spawn Scp-q-P $src _path $dst _path
Set Timeout 30
#expect –re ". *assword:\r"
Send "$passwd \ r"
Set Timeout 30
Send "exit\r"
Expect EOF

3. Assigning Executable Properties

chmod +x expect_scp_one.sh

chmod +x copycgi.sh

4. Test

./copycgi.sh./
Spawn Scp-q-P./mp_credit_userinfo.cgi logview@172.25.38.13:/usr/local/www.aaa.com/app/mpay/
LogView
Exit
logview@172.25.38.13 ' s Password:
Received Signal 1. (No core)
Send./mp_credit_userinfo.cgi finish

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.