LinuxQuestions.org
Register a domain and help support LQ
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 10-19-2016, 04:51 AM   #1
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 14 & 15
Posts: 73

Rep: Reputation: Disabled
Wildcards


I have a script that writes some information to a text file of system health every few minutes with a date stamp in the filename, ie pi-2-black_status_161018_0000.txt.

I'm writing another script to search that directory and do something if it does not see any files created in the last 60 minutes.

I'm failing on 2 issues. First one is I can't seem to use wildcards when searching. In the example below it will search for the existence of 'pi-2-black_status_161018_0000.txt' which works fine. However if I change the search to 'pi-2-black_status_??????_????.txt' it doe's not work.

Code:
#!/bin/bash

SEARCHFILE="/home/tim/Documents/pi-2-black/status/pi-2-black_status_161018_0000.txt"

if [ -f "$SEARCHFILE" ]
then
echo "Found"
else
echo "Not found"
fi
Secondly, how do I add an, 'if file older than 60min' into the search, I thought I could place -mmin +60, however that does not appear to work.

Many thanks for any help.
 
Old 10-19-2016, 05:12 AM   #2
Turbocapitalist
Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 976
Blog Entries: 3

Rep: Reputation: 396Reputation: 396Reputation: 396Reputation: 396
-name

For the first question, when you wrap anything in quotes the symbols take on a literal meaning and are no longer used for globbing

For the second question, it looks like you are talking about "find", you have to use some gymnastics to get something useful out of it because it generally returns 'success' regardless of whether a file was found or not.

Code:
if test "$(find /path/to/some/dir/ -name 'something.txt' -mmin +40 -print | wc -l)" -ne 0; then echo OK; fi
Though there is probably a better way for that.

Last edited by Turbocapitalist; 10-19-2016 at 05:27 AM.
 
1 members found this post helpful.
Old 10-19-2016, 08:12 AM   #3
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,433

Rep: Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353Reputation: 1353
Quote:
I'm writing another script to search that directory and do something if it does not see any files created in the last 60 minutes.
An alternative may be to use a temporary file.
Code:
searchdir="/home/tim/Documents/pi-2-black/status/"
timestamp="/tmp/timestamp.tmp"

touch -d "-1 hour" "$timestamp"

for f in "$searchdir"pi-2-black_status_??????_????.txt; do
  if [ "$f" -ot "$timestamp" ] ; then
    echo "$f is older"
  else
    echo "$f is newer"
  fi
done

rm "$timestamp"

Last edited by allend; 10-19-2016 at 08:15 AM.
 
1 members found this post helpful.
  


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
Cp with wildcards Fixit7 Puppy 4 11-17-2014 01:20 AM
Wildcards randalleg Linux From Scratch 3 06-19-2011 09:09 AM
need help with wildcards liorpana Programming 2 05-12-2010 09:45 AM
using wildcards nadroj Linux - General 5 01-28-2007 09:39 PM
Wildcards dazdaz Linux - Newbie 3 01-23-2005 06:33 AM


All times are GMT -5. The time now is 04:31 AM.

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