The code snips are helpful code that shows similar problems and solutions from a website, job control.
What is wrong with this code?
Code:#!/bin/bash trap_key=false # capture the interrupt control-c trap 'trap_key=controlc' 2 clamscan -r / if [ trap_key = 'controlc' ]; then printf "clamscan interrupted\n" else printf "clamscan completed fi
I want control-c to cancel clamscan and return to the script. The variable controls the print. Prints results if control-c was pressed or not.
The code snip I included looks like it does that. I have not had chance to test it yet.
I think I know what is happening, thanks to help from here. Control-c is working, but it's causing an error "unexpected EOF" which causes the script to drop to the command line. I'm using a loop which I didn't add into writing my simple script. I forgot to add a control-c flag inside the a loop and need go back over the scanvirus script.
There are two ways I'v found to catch this error.
http://redsymbol.net/articles/bash-exit-traps/
Using signal exit to unmount the drive if the script exits for any reason. The link shows how to use the exit signal to restart a script if it crashes.
http://stackoverflow.com/questions/6...-in-bash#69808
Using sig error to trap this error.
Thanks for the help all.
I'll have to come back to this problem later. A new error appeared on my SED stream filter line on scanvirus script.
I found an alternative method to fix the problem, using the 'trap function exit'.
Thanks to all for the help....
Bookmarks