[ale] shell scripting baby questions...

David S. Jackson deepbsd at earthlink.net
Fri Feb 27 12:31:11 EST 2004


On Fri, Feb 20, 2004 at 10:54:25AM -0500 Keith Morris - IQ <keith at iqtv.com> wrote:
> #!/bin/bash
> #
> # Script to run BitDefender nightly and report
> # the full scan as well as create an infected
> # file report
> #
> 
> # file and path variables
> reportTime=`date +%y%m%d_%H%M%S`;
> logName="scan_$reportTime.log";
> infectedLogName="infected_$reportTime.log";
> logPath="/home/samba/production/vlogs";
> dirToScan="/home/samba/production";

Just FYI, you don't really need the ';' at the end of each line like
you do in perl.  I don't think it does any harm, except that it might
confuse you or someone else looking over your source.  You might
start putting spaces in variable assignments like: blah = "whatever";
as you would in perl!  :-)


> # update virus defs
> /opt/bdc/bdc --update;
> 
> # run virus scan with logging
> /opt/bdc/bdc --arc --disinfect --log=$logPath/$logName $dirToScan;
> 
> # list all found infected files into an infected log
> cat $logPath/$logName | grep infected: > $logPath/$infectedLogName;
> 
> # find out if there were any found infections
> infectionsDetected=`cat $logPath/$infectedLogName | wc -l`;
> 
> # if no virii were detected, deleted infected log file.
> # *!!! this ain't workin' !!!*
> 
>  if [ $infectionsDetected eq "0" ]

you heard about -eq not eq...

>  then
>    rm -f $logPath/$infectedLogName

you could shorten this if clause to 

[ -z "$infectionsDetected" } && rm -f $logPath/$infectedLogName

I think it would be a little more efficient.

>  fi
> 
> # tar and gzip the scan logfile and remove the uncompressed log
> tar -czf $logPath/$LogName.tgz $logPath/$infectedLogName;
> rm -f $logPath/$logName;

[ -f "$logPath/$logName" -a -w "$logPath/$logName" ] && rm $logPath/$logName

Just to get into the habit of checking files before you operate on
them.

Nice script!


-- 
David S. Jackson                                dsj at dsj.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
A door is what a dog is perpetually on the wrong side of.
		-- Ogden Nash



More information about the Ale mailing list