最后,我读了一些博客,我建立了一个脚本来使用SCP来备份远程文件并压缩后:
#!/usr/bin/sh
set IP [lindex $argv 0]
set EQ [lindex $argv 1]
set NOW [exec date "+%Y%m%d"]
mkdir /tftpboot/tmp/$EQ
#
expect <<'END'
spawn scp -rpc "sadmin@$IP:/usr/local/etc/*" /tftpboot/tmp/$EQ
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
exp_send "Ti3OlEwP8h4\r"
}
}
interact
END
#
tar cf - /tftpboot/tmp/$EQ | 7za a -si /tftpboot/2015/$EQ.$NOW.tar.7z
#
rm -rf /tftpboot/tmp/$EQ
但是当我运行它时会收到此错误:
# ./testbk.sh 1.1.1.1 TestServer > log.txt
mkdir: Failed to make directory "/tftpboot/tmp/"; File exists
can't read "IP": no such variable
while executing
"spawn scp -rpc "sadmin@$IP:/usr/local/etc/*" /tftpboot/tmp/$EQ"
我系统上的其他一些数据:
# echo $tcsh
6.08.00
# echo $version
tcsh 6.08.00 (Astron) 1998-10-02 (i386-sun-solaris) options 8b,nls,dl,al,rh,color
# uname -a
SunOS CSPC2 5.10 Generic_144489-17 i86pc i386 i86pc
# cat /etc/release
Solaris 10 6/06 s10x_u2wos_09a X86
Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 09 June 2006