#create LinuxScanFolders cfg file if not present
if -f "/var/log/VirusVault/scanvirus.cfg" ]]; then
printf ""
else
printf "creating LinuxScanFolders
"
cat > /var/log/VirusVault/scanvirus.cfg <<EOL
__________scanvirus configuration__________
___________________________________________
Excluded Scan Folders
etc dev proc tmp mnt media srv .snapshots
___________________________________________
Time Date Stamp
date '+%Y-%m-%d %I:%M%P'
___________________________________________
EOL
fi
#setup configuration lines into array
IFS=$'
' read -d '' -r -a lines < /var/log/VirusVault/scanvirus.cfg
printf "excluded folders: %s
" "${lines[3]}"
printf "time date stamp : %s
" "${lines[6]}"
Time_Date_Stamp=$( "${lines[6]}" )
# check for date command error
#if $? != 0 ]]; then
# echo "----- Time_Date_Stamp error -----"
# exit 1
#fi
printf "%s
" $Time_Date_Stamp
It checks for the config file. Creates it if needed. Then reads the file lines into an array. Assigns the time_date_stamp from a line in the file.
excluded folders: etc dev proc tmp mnt media srv .snapshots
time date stamp : date '+%Y-%m-%d %I:%M%P'
./scanvirusa: line 136: date '+%Y-%m-%d %I:%M%P': command not found
From the error message we can infer bash is taking the whole line as the command name, whereas we want only “date”. You could remove double quotes from the command, but from a quick test it seems it’s doing word splitting, ignoring the single quote. I wish I knew why.
If you can change the format in the .cfg file, I suggest you omit the “date” part, and prepend the date command before the quoted line. Not a definitive solution, but may work in your case.
The backticks are evaluated at the time of “cat <<EOL”, it means the .cfg file holds now a timestamp instead of a format. To avoid that, use “cat <<‘EOL’” (single quote EOL) but that leads to the original issue.
The proper format for readable code should be that: Date_Time_Stamp
However the user can make the stamp in any format they like. The stamp is used on some folders[ostype stamp]. The virus logs (-vl) has it’s own stamp(for sorting) first then user’s format. It’s very large script.
Yes, direct line number references will cause problems if the user alters the file. But, I need to get the code working first before I make more error checking and reformat the file. The script is still missing lots of error checking.
Sorting by date is done by the vl function. I don’t have it by hour and day. Unless someone requests it by the hour, I’m going to leave it out. By year-month-day is next on my list.
view logs
p1: -vl
p2: l or m mask by linux/mswin scans (optional)
p2: d mask by date (optional)
p3: year (optional)
p4: month (optional)
Yes, putting filenames with spaces has caused me a lot of problems. One reason I never called it a stable release, all kinds of design flaws.
I can use the TR command before displaying filenames with underscores.