Question

I'm trying to script bacula to delete old files that are not used any more. While there are over 1000 old files im not willing to do it manualy.

How far I've come

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

But now I have the problem of the security question where someone have to enter "yes"/"no".

Are you sure you want to delete Volume "2012-10-19_23h40m"? (yes/no)

But the bconsole program is just exiting!

Any ideas?

Was it helpful?

Solution 2

@brain thanks for the input but I like one liner :D

what is nearly a one-liner and works like charm

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

so you can skript everything with an interactive programm :D

OTHER TIPS

Maybe throw a little expect(1) into the mix?

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

So your loop would look like this (I'm assuming the 2012-10... part will eventually be replaced by what you found in the pipeline, but without knowing how that would work, I'm just using what you've got in the question)...

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

Usual caveats apply. I am by no means an expect expert, so testing this before going live is highly recommended. :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top