I just could not leave the script working half way.
I made the script check for all running processes before it updates the cvd files in the /var/clamav directory.
Code is never perfect.
The program now will wait on any clamscan, clamd or freshclam processes running, at least it is suppose to.
After all those processes have no activity(freshclam runs 2 processes while updating and 1 process when idle no updating ClamAVand).
The script will stop the service of freshclam and clamd, then update the cvd files, then restart the clamd and freshclam services in that order.
The timing in the checking for freed up clamd processes maybe too loose for a busy server, specially where heavy ClamAV activity maybe accessing and checking emails.
If outputmsg is set 1, the output of the routine should give some valuable information. If ClamAV processes never free up. This script will never end the way it is written.
Because some clamscan virus scans can take hours. This program script was desgined not to give up while clamscan is running, but the script will wait on clamscan to finish, then update the cvd files when there is no activity. Once again, that is where I put in a time of day variable for the script to actually do its work if the user wants to use that option.