日期:2014-05-16  浏览次数:20735 次

怎样在bash脚本中使用scp,怎样在脚本中自动输入命令

1.在bash脚本里怎么使用scp啊,自己弄个脚本,结果提示错误。
2.想在执行scp命令的时候自动输入密码,应该怎么实现啊?

#/usr/bin/bash
files=./flist.txt
usr=byang
ip_addr=192.168.0.4

cat $files | while read oneline
do
    #scp byang@192.168.0.4://usr/home/byang/work/head/bti-freebsd/crypto/openssl/crypto/x509v3/v3_pci.c ./
    src_file=$oneline
    tag_file=$oneline
    src_path=${usr}@${ip_addr}://usr/home/byang/work/head/${src_file}
echo src_path:${src_path}
    tag_path=./${tag_file}
#echo tag_patch:${tag_path}
    echo `scp ${src_patch} ${tag_path} 0<pswd `
done
执行结果显示如下:为什么啊?

usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2


------解决方案--------------------
据说可以用expect,,,但我还没学。。。简单的使用上手估计也快。
------解决方案--------------------
楼主搜索下linux expect
------解决方案--------------------
先配好信任吧.