2012-10-23 26 views
1

我正在嘗試腳本bacula刪除不再使用的舊文件。雖然有超過1000箇舊文件我不願意這樣做manualy。阻止bacula腳本中的安全查詢

我已經走了多遠

for filename in $(echo "list volume" |bconsole |grep Purged |awk -F\| '{print $3}') 
do 
    echo "delete volume=2012-10-19_23h40m" | bconsole 
done 

但現在我有安全問題,如果有人要進入「是」 /「否」的問題。

是否確定要刪除卷「2012-10-19_23h40m」? (是/否)

但是,bconsole程序正在退出!

任何想法?

回答

1

@brain感謝輸入,但我喜歡一個班輪:d

什麼是近一個班輪和作品般的魅力

for filename in $(echo "list volume" |bconsole |grep 2012-08 |awk -F\| '{print $3}'); do bconsole << EOF; rm /media/storage/$filename; done 
delete volume=$filename 
yes 
quit 
EOF 

這樣你就可以用一個交互式skript一切程序:D

1

也許扔一點expect(1)到混合?

bash$ cat delete_volume 
#!/usr/bin/expect 

# Start up bconsole 
spawn bconsole 

# Grab the command from STDIN 
expect_user -re "(.*)\n" 

# Send it to bconsole 
send "$expect_out(1,string)\n" 

# Handle the Q&A 
expect "Are you sure" { send "yes\n" } 

# Let bconsole do its work 
interact 

所以,你的循環應該是這樣的(我假設2012-10 ...一部分最終會被你的管道找到了更換,但不知道如何將工作,我只是使用你的問題)...

for filename in (...your file finding pipeline...) 
do 
    echo "delete volume=2012-10-19_23h40m" | ./delete_volume 
done 

通常的警告適用。我絕不是一位期望專家,所以強烈建議您在上線前進行測試。 :-)