I want to filter the svlog file by date and split the result by the space, so when i enter the date, it didn't work for me, please refer to the script that I wrote below, the problem was in this command:
ligne=`cat /var/log/svlog | grep "\$day"`
, it doesn't consider "\$day". i also tried this "^\$day", this "$day" and this "${day}" but the same result.
#!/bin/bash
echo SCRIPT-LOG
echo enter date
read day
ligne=`cat /var/log/svlog | grep "\$day"`
$ligne >> log1.txt
awk '{split($ligne,numbers," ")} END {for(n in numbers){ print numbers[n] }}'>lo
"Monit_Sub.sh" 11 lines, 211 characters
$ sudo ./Monit_Sub.sh
SCRIPT-LOG
enter date
Apr 26
./Monit_Sub.sh: line 8: Apr: command not found
$
cat /var/log/svlog | grep "\$day"
with this quotes (`) – faimer Apr 26 '16 at 14:38echo
so your script is trying to execute a command called Apr. That's the specific error you've got, I've not considered anything else in your script. – EightBitTony Apr 26 '16 at 14:41$ligne >> log1.txt
supposed to execute the command stored in$ligne
and append its output intolog1.txt
(that's what it does) or was it supposed to append the contents of the variable$ligne
to the file? Yourawk
command has no input, what is that supposed to do? Please [edit] and clarify. – terdon Apr 26 '16 at 14:58$(this syntax)
for command substitution instead of backticks; the quoting is MUCH easier. – Wildcard Apr 26 '16 at 23:43