远程 ls 输出未重定向到文件

Remote ls output is not redirecting to file

当我运行下面的代码时,我收到了这个错误

bash: /var/out.txt: No such file or directory

#!/usr/bin/expect

set timeout -1    
spawn ssh user@10.103.234.1 'ls -t /var/backups/archives/' > /var/outp.log    
expect "user@10.103.234.1's password:"    
send "Password\n"    
expect eof

if [catch wait] {    
    puts "failed"    
    exit 1    
}

exit 0

Expect/Tcl 不理解重定向 (>) 字符。试试这个:

spawn bash -c "ssh user@10.103.234.1 ls -t /var/backups/archives/ > /var/outp.log"

使用 T 恤更换 生成 ssh 用户@10.103.234.1 'ls -t /var/backups/archives/|tee -a /var/outp.log'