linux - Delete everything other than file + linked file across multiple servers (NET::SSH::MULTI) -
linux - Delete everything other than file + linked file across multiple servers (NET::SSH::MULTI) -
i've got couple of one thousand images saved logs need deleted.
to avoid limit of rm , across multiple servers, used next code
net::ssh::multi.start(:on_error => :ignore) |session| # define servers in groups more granular access session.group :app session.use 'example@example', :password=> 'example' end # execute commands on subset of servers session.with(:app).exec "find /tmp/motion -maxdepth 1 -not -name 'lastsnap.jpg' -print0 | sudo xargs -0 rm" end
an ls -l lastsnap.jpg shows lastsnap.jpg linked file,
30 jun 3 08:18 lastsnap.jpg -> 81-20140603081840-snap.jpg
this other file changed due logging scenario mentioned above.
reiterating question, how delete every other logged file not lastsnap.jpg , it's linked file.
thanks help :)
cd /tmp/motion ls -1 | grep -v -e '$(basename `find . -lname lastsnap.jpg`)|lastsnap.jpg' | while read n ; rm -rvf $n ; done
edit per comment
cd /tmp/motion; rm -rvf $(ls -1 | grep -v -e "$(basename `find . -lname lastsnap.jpg`)|lastsnap.jpg")
note: create sure file names don't have spaces in it. other wise method not work , needs modification in order accommodate spaces in file name.
linux unix ssh net-ssh
Comments
Post a Comment