LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-01-2012, 05:53 PM   #1
ratotopi
Member
 
Registered: Dec 2011
Posts: 114

Rep: Reputation: 6
command find, wildcard and bash script howto


I am trying to run the command
find /var/log/httpd -iname access_log-201204* > /tmp/accesslist
from the bashscript but I cannot get it to work. How do I provide the * wildcard in bash script for the following script. I am trying to make a list of all the previous months access_log files

#!/bin/bash
YESTERDAY=`date -d " -1 day" +%Y%m%`
NOW=`date +%d`

if [ $NOW== "1" ]; then
find /var/log/httpd -iname access_log-$YESTERDAY > /tmp/filename
else
exit 0
fi


thank you for your help.
 
Old 05-01-2012, 06:15 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Put it in quotes

Code:
find /var/log/httpd -iname "access_log-201204*" > /tmp/accesslist
Without quotes your shell is expanding the access_log-201204* to all matches and then passing them into find

Last edited by suicidaleggroll; 05-01-2012 at 06:16 PM.
 
Old 05-01-2012, 06:58 PM   #3
ratotopi
Member
 
Registered: Dec 2011
Posts: 114

Original Poster
Rep: Reputation: 6
@suicidaleggroll
see my script I cannot execute the following command with * at the end of $YESTERDAY can I ??

find /var/log/httpd -iname access_log-$YESTERDAY* > /tmp/filename
 
Old 05-01-2012, 07:03 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Sure, but you need to put it in quotes

Code:
$ ls
access_log-20120405  access_log-20120407  access_log-20120506
access_log-20120406  access_log-20120505  access_log-20120507
$ YESTERDAY=`date -d "-1 day" +%Y%m`
$ echo $YESTERDAY
201204
$ find . -iname "access_log-$YESTERDAY*"
./access_log-20120407
./access_log-20120406
./access_log-20120405
 
Old 05-01-2012, 07:46 PM   #5
ratotopi
Member
 
Registered: Dec 2011
Posts: 114

Original Poster
Rep: Reputation: 6
@suicidaleggroll
thanks!! I was amazed you could run that script and I couldn't, so I check the script again and found % at the end of YESTERDAY=`date -d " -1 day" +%Y%m%` that was creating the problem. Removed the % and it worked , my silly mistake.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wildcard/regex in bash command logicalfuzz Linux - General 2 10-27-2011 03:40 PM
Find command to search wildcard in path? markdjones82 Linux - General 12 12-11-2009 02:02 AM
Bash script with find command dexznrl Programming 6 08-10-2009 01:52 PM
script for a command that won't accept wildcard value hemp4fuel Programming 4 05-24-2004 06:30 AM
same find command not working in bash script, quotes? QuakerOatz Linux - Software 1 07-14-2003 01:04 PM


All times are GMT -5. The time now is 06:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration