我想使用纯期望脚本而不调用外部shell来执行tar和rm操作。我当前的结果是有效的,但使用外部bash脚本。
P.S。我所有尝试从期望脚本执行tar或rm的尝试都失败了。
主要脚本
#!/usr/bin/expect
# my scripts folder is here:
set myhome /home/scripts
set fullBpath /home/backup/SDH/
set date [exec date +%F_%k-%M]
# Some expect script commands was removed here.
exec $myhome/zip_clean.sh $fullBpath $date
send_user "Script terminated.\n"
exit
zip_clean.sh
#!/bin/bash
cd $1
tar cvzf OME6500-Backup-$2 *.cmp *.inf
rm *.cmp *.inf
答案 0 :(得分:0)
您可以使用命令file和命令glob。也 使用日期时,您可以使用clock:
set date [clock format [clock seconds] -format %Y-%m-%d_%k-%M]
cd $fullBpath
exec tar cvzf OME6500-Backup-$date [glob *.cmp *.inf]
file delete [glob *.cmp *.inf]
答案 1 :(得分:0)
发现并测试非常简单的方法:
system "cd $fullBpath; tar --remove-files -cvzf OME6500-Backup-$rundate.tgz *.cmp *.inf"