I'm having a heck of time getting a silly little awk script to run correctly. I know I'm not escaping/quoting the variable correctly, but I cannot figure out what's wrong.
Objective, match a leading (time) string in a logfile and print the rest of the file from that matching poing to the end of the file:
This works on the command line
This works on the command line
(it outputs the expected output
This works in a bash shell script
This works in a bourne shell script
However, when I change the awk to use a variable $FOOFOO, the script generates no output... examples of brokenness
This generates an error while parsing the variable
Can anyone shortcut my fast trip to shell variable quoting madness? THANKS!
D.E.R. Management - IT Project Management Consulting
Objective, match a leading (time) string in a logfile and print the rest of the file from that matching poing to the end of the file:
This works on the command line
Code:
> date --date="1 hour ago" +'%b %d %H:%M'
May 29 09:05
This works on the command line
Code:
export FOO=`date --date="1 hour ago" +'%b %d %H:%M'` | tail -5000 auth.log | awk '/^May 29 06/,EOF'
This works in a bash shell script
Code:
#!/bin/bash
FOOFOO=`date --date="1 hour ago" +'%b %d %H:%M'`
SOURCELOG="/var/log/auth.log"
tail -5000 $SOURCELOG | awk '/^May 29 06/,EOF'
This works in a bourne shell script
Code:
#!/bin/sh
FOOFOO=`date --date="1 hour ago" +'%b %d %H:%M'`
SOURCELOG="/var/log/auth.log"
tail -5000 $SOURCELOG | awk '/^May 29 06/,EOF'
However, when I change the awk to use a variable $FOOFOO, the script generates no output... examples of brokenness
Code:
awk '/^$FOOFOO/,EOF'
awk '/^${FOOFOO}/,EOF'
awk '/^{${FOOFOO}}/,EOF'
awk '/^{$${FOOFOO}}/,EOF'
This generates an error while parsing the variable
Code:
awk '/^'$FOOFOO'/,EOF'
awk: /^May
awk: ^ unterminated regexp
Can anyone shortcut my fast trip to shell variable quoting madness? THANKS!
D.E.R. Management - IT Project Management Consulting