2

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.

1 Answer 1

1

If you'd like more info on bash you can type man bash to read the online manual.

-eq is the correct operator for testing if numbers are equal.

? (without the dollar sign) "Matches a single character" when doing filename pattern matching. $? is a Special Parameter that "Expands to the status of the most recently executed foreground pipeline" (for your purposes "foreground pipeline" just means command)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .