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

问一个shell脚本的问题
   最近公司要搞日志分析,我选用了awstats来分析日志,都搭建好了,因为想让它自动运行于是想写一个shell脚本来从远程服务器复制日志文件到本地的服务器,可是写完后发现运行怎么都通不过,.sh文件的权限已经设置好了。OK,直接上shell脚本的代码


#/!bin/sh
#author: wxh

#ip
ip="192.168.1.100"
#服务器账号
user="root"
#服务器密码
pwd="ALEX885901"
#源文件地址
src_file=/home/log/apache/logs/access."+%Y_%m_%d".log
#本地文件地址
dest_file=/home/log/


spawn scp $user@$ip:$src_file $dest_file
 expect {
 "(yes/no)?"
   {
    send "yes\n"
    expect "*assword:" { send "$pwd\n"}
 }
 "*assword:"
{
 send "$pwd\n"
}
}
expect eof
linux apache shell shell脚本 scp命令

------解决方案--------------------
spawn scp $user@$ip:$src_file $dest_file
 expect {
 "*yes*"
   {
    send "yes\n"
    expect "*assword*" { send "$pwd\n"}
 }
 "*assword*"
{
 send "$pwd\n"
}
}
send "exit\r"
expect eof