Sponsored Content
Top Forums Shell Programming and Scripting Scan and remove if file infected using bash Post 302990264 by cmccabe on Tuesday 24th of January 2017 07:53:12 AM
Old 01-24-2017
So if I am following correctly, something more like:

Code:
#!/bin/bash
DIR=/home/cmccabe/Desktop/NGS/API
log=$HOME/virus-scan.log

{
echo "The extensions are"
ls | awk -F'\.' 'NF>1 {ext[$NF]++} END {for (i in ext) print ext[i],i}'
} > $log

scanned=0
for FILE in "$DIR"/*
do
     # check file length is nonzero otherwise commands may be repeated
     if [ -s "$FILE" ]; then
          {
          date
          clamscan -r "$FILE"
          } >> $log
          ((scanned++))
          while read line
          do
              line="${line% FOUND}"
              virus_name="${line#* }"
              file_name="${line%: *}"
              ((virus_count=$virus_count+1))

              printf "  %s\n" "${file_name}"            # Output to screen
              printf "%s\n" "${file_name}" >&3          # Output to log
          done < <(grep " FOUND$" $scan_log) 3>log
          echo "The files infected have been moved to the folder at /home/cmccabe/quarantine"
        fi
     fi
done
[ $scanned -eq 0 ] && echo "nothing detected by scan" >> $log

Thank you for your help Smilie.

Last edited by rbatte1; 01-24-2017 at 09:50 AM.. Reason: Adjusted indenting for clarity
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Scan

Hi everyone , i m working on Sun solaris and i have a file "smsapp.cur" which has information like this paragraph given below , there are millions of such paragraphs From:923212802736 To:923222326807 logMessage: 07-04-08 17:34:29 Getting message topup from code page default in language English... (2 Replies)
Discussion started by: Dastard
2 Replies

2. Shell Programming and Scripting

how can i remove comments in random positions in a file?(bash)

Suppose i have a file like this: #bla bla #bla bla bla bla bla Bla BLA BLA BLA #bla bla .... .... how can i remove all comments from every line,even if they are behind commands or strngs that are not comments? any idea how i could do that using awk? (2 Replies)
Discussion started by: bashuser2
2 Replies

3. Windows & DOS: Issues & Discussions

Internet Explorer is infected - small windows keep popping up

hello, I have an annoying problem on my Internet Explorer. When I open that browser, after some time advertisement windows just pop up, even if I am not browsing anything, or when the browser is running at the background. That is, the pop-ups don't come from the websites I visit, rather, I... (17 Replies)
Discussion started by: milhan
17 Replies

4. Shell Programming and Scripting

How to get rid of cannot remove file error in bash script?

Hi Guys, I am creating a couple of temp. files in a script. After completing the script, I am using the rm command to delete these files. The files are getting deleted but I am getting "filename - cannot find file;no such file or directory" error in my bash shell terminal window. I am using... (3 Replies)
Discussion started by: npatwardhan
3 Replies

5. What is on Your Mind?

iPad infected with virus

What to say nothing is no more secure Apple's new iPad has been taken down by malware within a few weeks of it being in the shops. It is an article of faith amongst Apple fanboys that Jobs' Mob gear is super secure and malware only exists on Windows machines. Despite the fact that Apple gear... (1 Reply)
Discussion started by: solaris_user
1 Replies

6. Shell Programming and Scripting

scan and edit in bash

so assume I have a dozen files in local directory and half of them are .txt and I only want to scan these text files and go inside each of them and replace absolute paths (e.g. C:\blabla\more blahblah\myfile.txt) with just the name of that file (myfile.txt) and then go to next line and look if... (6 Replies)
Discussion started by: Jaymz
6 Replies

7. Shell Programming and Scripting

How to remove '^[[00m' in bash file?

Hi, This should be a simple one: I run the following commands in bash and ksh respectively but got differenant results: # ls -l /var/log > /tmp/a # vi /tmp/a In bash shell, I got: ^ In ksh, I got: total 828552 -rw-r----- 1 root root 189 Aug 9 00:00 acpid -rw-r----- 1 root... (7 Replies)
Discussion started by: aixlover
7 Replies

8. Shell Programming and Scripting

Remove original file from directory after bash executes

The below bash works great, except I can not seem to delete the original file $f from the directory. Thank you :) For example, after the bash executes there are 8 files in the directory: 123.txt (original file) 123_remove.txt 123_index.txt 123_final.txt 456.txt (original file)... (11 Replies)
Discussion started by: cmccabe
11 Replies

9. Shell Programming and Scripting

Create automated scan of specific directory using bash

I am trying to use bash to automate the scan of a specific directory using clamav. Having this in place is a network requirement. The below is an attempt to: 1. count the extensions (.txt, .jpeg) in a directory and write them to a virus-scan.log (section in bold) 2. scan each folder in the... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. UNIX for Beginners Questions & Answers

Bash to remove find and remove specific extension

The bash below executes and does find all the .bam files in each R_2019 folder. However set -x shows that the .bam extension only gets removed from one .bam file in each folder (appears to be the last in each). Why is it not removing the extension from each (this is $SAMPLE)? Thank you :). set... (4 Replies)
Discussion started by: cmccabe
4 Replies
Clamd client(1) 						  Clam AntiVirus						   Clamd client(1)

NAME
clamdscan - scan files and directories for viruses using Clam AntiVirus Daemon SYNOPSIS
clamdscan [options] [file/directory] DESCRIPTION
clamdscan is a clamd client which may be used as a clamscan replacement. It accepts all the options implemented in clamscan but most of them will be ignored because its scanning abilities only depend on clamd. OPTIONS
-h, --help Display help information and exit. -V, --version Print version number and exit. -v, --verbose Be verbose. --quiet Be quiet - only output error messages. --stdout Write all messages (except for libclamav output) to the standard output (stdout). --config-file=FILE Read clamd settings from FILE. -l FILE, --log=FILE Save the scan report to FILE. -f FILE, --file-list=FILE Scan files listed line by line in FILE. -m, --multiscan In the multiscan mode clamd will attempt to scan the directory contents in parallel using available threads. This option is espe- cially useful on multiprocessor and multi-core systems. If you pass more than one file or directory in the command line, they are put in a queue and sent to clamd individually. This means, that single files are always scanned by a single thread. Similarly, clamdscan will wait for clamd to finish a directory scan (performed in multiscan mode) before sending request to scan another direc- tory. This option can be combined with --fdpass (see below). --remove Remove infected files. Be careful. --move=DIRECTORY Move infected files into DIRECTORY. --no-summary Do not display summary at the end of scanning. --reload Request clamd to reload virus database. --fdpass Pass the file descriptor permissions to clamd. This is useful if clamd is running as a different user as it is faster than streaming the file to clamd. Only available if connected to clamd via local(unix) socket. --stream Forces file streaming to clamd. This is generally not needed as clamdscan detects automatically if streaming is required. This option only exists for debugging and testing purposes, in all other cases --fdpass is preferred. EXAMPLES
(0) To scan a one file: clamdscan file (1) To scan a current working directory: clamdscan (2) To scan all files in /home: clamdscan /home (3) To scan a file when clamd is running as a different user: clamdscan --fdpass ~/downloads (4) To scan from standard input: clamdscan - <file_to_scan cat file_to_scan | clamdscan - RETURN CODES
0 : No virus found. 1 : Virus(es) found. 2 : An error occured. CREDITS
Please check the full documentation for credits. AUTHOR
Tomasz Kojm <tkojm@clamav.net> SEE ALSO
clamd(8), clamd.conf(5), clamscan(1) ClamAV 0.96.1 February 12, 2009 Clamd client(1)
All times are GMT -4. The time now is 01:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy