I’m trying to execute this command in in a bash script
find /var/log/apache2/access*.gz -type f -newer ./tmpoldfile ! -newer ./tmpnewfile | xargs zcat | grep -E '$MONTH\/$YEAR.*GET.*ad=$ADVERTISER HTTP\/1' -c
If i execute it directly or assign it to a variable it returns 0
But if i do a echo of the command (with the variables replaced by the script) and execute it in the command line it works.
echo "find /var/log/apache2/access*.gz -type f -newer ./tmpoldfile ! -newer ./tmpnewfile | xargs zcat | grep -E '$MONTH\/$YEAR.*GET.*ad=$ADVERTISER HTTP\/1' -c"
How shold i code it for work
Variables aren’t expanded inside of single quotes, i.e. ‘…$NOT_EXPANDED …’. Try
Same for “or assign it to a variable “
Also, I must comment on
-exec. Many finds now supportfind ... -exec ... \+which is (I assume) the equivalent ofxargs, but not all OS’s have GNU find as their first tool. If you’re sure you’ll never work in a Solaris, AIX, or HPUX shop, then use the improved features. Also, if you’re using new OS’s, thenxargslikely supports parallel processing, which I don’t thinkfind ... -exec ... \+will do.I hope this helps.