How do I parse a textfile to move some files?
Hi,
I use avg free as antivirus scanner. I looked some time for a scanner to scan and remove viruses. Problem is avg 8.5 will only detect viruses, not remove them... I use a oneliner looking like this: Code:
/usr/bin/avgscan / -x /mnt -x /dev --heur --ignerrors -r /var/log/"scanlog"`eval date +%Y%m%d`".txt" Code:
AVG command line Anti-Virus scanner Now I want to parse that file to pick the infected files and use mv to secure the system.. is there any way to acomplish that? I guess I could start with looking for the lines starting with / evaluate them so when they get two spaces, then it cuts. (Filename comes first, then two spaces, then description of virus..) then use the line to mv the file someware. For instance /var/quarantine/ I know there are problably other programs that do work. But it took me some time to install and figure out this one, and now when I got it working it seems like avg has stopped the healing function in this upgrade.. They are "working on it".. If you have a tip about a free anti-virus software that is easy to figure out, it would be nice. But I would also like to learn some parsing. This was a bit tuff for me right now. But if someone please can get me started im shure I can figure it out. I know a bit of bash and php, not so much about pearl but anything is apreciated. |
Well you have a few options; you can try this with Bash using a for loop and the cut command, or you can use your favourite scripting language, up to you.
A 30second script in python to do this simply: Code:
#!/usr/bin/env python |
hmm, thanks
Tried it on some sample outputs, and it seems to work. Have to try a bit more. Dont know much about python, but I think i understood most of it, but I have to try to search a bit to understand how to use dates and to move files, but this is a good starter. Tx.
|
Well, python has an interactive shell; so type in 'python' at a terminal. Libraries are imported with 'import', and every library/module/$terminology, assuming documented properly, is can be called in 'help()' as so:
Code:
>>> import time But yes, there are neater and smaller ways, but the above is quick, efficient and easy enough to change and adapt. EDIT: Just realised I made a mess of the first example anyway; Code:
#!/usr/bin/env python |
Now I think it works
Hi again,
Tx for your clarification. I noticed that small miss with double spaces. Now I got it this far.. I changed the oneliner to: Code:
/usr/bin/avgscan / -x /mnt -x /dev --heur --ignerrors --hidext -r /var/log/"scanlog_"`eval date +%Y-%m-%d`".txt" Code:
# Open the file, try and find viruses |
Or....
Code:
#!/usr/bin/env python You may find it easier, incidentally, to use %s in strings that are using variables; http://homepage.mac.com/andykopra/pd...n_strings.html has a quick skim on it if you're not a C programmer (Where we use this sort of thing a lot). Basically, the first %s a string. We define this at the end: Code:
s = "string" |
All times are GMT -5. The time now is 07:52 PM. |