I am trying to set up a script to automatically delete a .torrent file based on an output from transmission-remote.
transmission-remote http://localhost/transmission -l | grep 100% | grep Finished | awk '{print $10}' | xargs -I% -r -p -n 1 /bin/rm /mnt/samba/Dropbox/%.torrent
Here is my current output:
/bin/rm /mnt/samba/Dropbox/MyTorrent.torrent ?...y
/bin/rm: cannot remove `/mnt/samba/Dropbox/MyTorrent.torrent': No such file or directory
The name that is outputted is identical to the .torrent name
root@mfalc:/mnt/samba/Dropbox/# ls
MyTorrent.torrent
root@mfalc:/mnt/samba/Dropbox/#
Here is also what it looks like before the awk
root@mfalc:~# transmission-remote http://localhost/transmission -l | grep 100% | grep Finished | grep Done
12 100% 174.4 MiB Done 0.0 0.0 0.01 Finished MyTorrent
I have obscured the actual torrent name but, does anyone have any suggestions? Am I concatenating the .torrent extension with xargs correctly?
Well you don't need xargs for that, awk can do it for you (only that part):
awk '{print $10 ".torrent"}'
Even better awk can call rm on it:
awk '{system("rm -i " $10 ".torrent")}'
If you have space(s) in the torrent names:
awk '{system("rm -i " gensub(" ","\\\\ ","g",$10) ".torrent")}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With