I have a simple function which will give me past one hour log
past_hour_log(){
awk -v Date1=$(date -d"now 1 hour ago" "+%H:%M:%S") -v Date2=$(date -d"now 1 hour ago" "+%d") ' { if ($3 > Date1 && $2 >= Date2) {print $0}} ' /var/log/syslog
}
My function Output :
Oct 9 12:15:15 localhost-IdeaPad-980 systemd[1]: time has been changed
Oct 9 12:16:00 localhost-IdeaPad-980 systemd[1534]: time has been changed
Oct 9 12:17:00 localhost-IdeaPad-980 systemd-timesyncd[25237]: Synchronized to time server 91.189.91.157:123 (ntp.ubuntu.com).
Oct 9 12:17:01 localhost-IdeaPad-980 CRON[27685]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 9 12:17:01 localhost-IdeaPad-980 CRON[29613]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
So here on next line, I am trying to pass this function output into grep xargs to get a total count of the string given as input from input.txt
TIME_COUNT="$(cat input.txt | xargs -I{} grep {} past_hour_log | awk '{print $7}' | awk -F '?' '{print $1}' | uniq -c)"
But the output shows me below. Are there any ideas to achieve this?
grep: past_hour_log: No such file or directory
export -f past_hour_logbefore calculatingTIME_COUNTpast_hour_log. Could you fix those first and come back to us?