Bash script to run a clamscan on Ubuntu- how to use return values properly?
Posted
by
Marius
on Super User
See other posts from Super User
or by Marius
Published on 2012-03-31T04:11:18Z
Indexed on
2012/03/31
5:32 UTC
Read the original article
Hit count: 431
I'm trying to put together a simple script that will scan my home directory with clamscan
and give me a warning if any viruses were found. What I have so far is:
#! /usr/bin/env bash
clamscan -l ~/.ClamScan/$(date +"%a%b%d") -ir /home
RETVAL=$?
[ $RETVAL -eq 0 ] && notify-send 'clamscan finished. No viruses found'
[ $RETVAL -eq 1 ] && notify-send 'clamscan found a virus' && touch ~/Desktop/VirusFound
[ $RETVAL -eq 2 ] && notify-send 'clamscan encountered errors. Check the logs' && touch ~/Desktop/ClamscanError
find ~/.ClamScan/* -mtime +7 -exec rm {} \;
However, I'm unsure about a couple of things:
I'm always wary of using rm
- as far as I can tell, the find
command I've got should be deleting any log files that are more than a week old.
I'm also not entirely sure how the return value testing works- I've got a manual that briefly covers bash, which says that the meaning of $?
is "match one character", and I'm not entirely sure how that grabs the return value. Should I be using -eq
or =
for testing the return value? From what I can tell -eq
tests strings and =
tests numerals, but I'm not sure what the type of the return value is.
© Super User or respective owner