LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-30-2013, 01:21 AM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Rep: Reputation: 0
Question ambiguous redirection question.


Guys,

I have a simple question.

I am doing two "finds" and first one works fine without any question however for the second one I am getting error like "ambiguous redirect" .

Well this is becoming an interesting thing as the syntax is fine and don't think there is any issue with that.

First find statement.
Code:
find ${BASE_DIRECTORY} -path \*/input/* -type f -not -wholename "*/unused/*" -mmin +60 -print >> ${INPUT_FILES}
Second find statement.
Code:
find ${BASE_DIRECTORY} -path \*/error/* -type f -not -name "SS*" -not -name "AA*" -not -name "PQ*" -mmin +60 -print >> ${ERR0R_FILES}
So may i know why is the second statement giving us the grief?
 
Old 04-30-2013, 04:19 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,251

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Try saying the second one out loud ... I think you will find there is a word missing between each 'not name' combo.

I would also be curious why you want the first asterisk not interpreted but then leave the second raw for the -path argument??
 
1 members found this post helpful.
Old 04-30-2013, 05:53 AM   #3
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
I used 2>&1 | tee -a ${LOGFILE} and error disappeared. I don't think there is any word missing between "-not -name "AA*
as I believe that is what the syntax is? Moreover If I run the same command in shell it works fine except in shellscript.

I could not understand your second question.

Quote:
I would also be curious why you want the first asterisk not interpreted but then leave the second raw for the -path argument??
 
Old 04-30-2013, 05:57 AM   #4
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
I now understood your second question. For path, all I want is all is all those files which match following pattern.
Code:
h1/input/h2
f1/f2/f3/input/f3
f1/f2/f3/input/f4
f1/f2/f3/input/f5
meaning let there any no of directories/files before input and after input directory, I only want those files which are coming after "input" directory. make sense now?
 
Old 04-30-2013, 06:20 AM   #5
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 592

Rep: Reputation: 140Reputation: 140
Adding quotes around the variable seems to be a good way to deal with the "ambiguous redirect" message: You tend to get a better message when you've made a typing mistake -- and when the error is due to spaces in the filename, using quotes is the fix.
Code:
bash-4.2$ find ${BASE_DIRECTORY} -path \*/error/* -type f -not -name "SS*" -not -name "AA*" -not -name "PQ*" -mmin +60 -print >> "${ERR0R_FILES}"
bash: : No such file or directory

Last edited by whizje; 04-30-2013 at 06:29 AM.
 
Old 04-30-2013, 06:29 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by sysmicuser View Post
I now understood your second question. For path, all I want is all is all those files which match following pattern.
No. Grail's question was that why you used escape character i.e. \ (backslash) before first asterisk symbol in error, while you didn't escaped the trailing asterist symbol? You did:
Code:
... -path \*/error/*  ...
Whereas Grail asked that why you didn't do this:
Code:
... -path \*/error/\* ...
Quote:
I used 2>&1 | tee -a ${LOGFILE} and error disappeared.
You have just redirected the std error, but error is still there.

However, once invoke command without redirecting it's output to a file, and check where you're getting error:
Code:
~$ find ${BASE_DIRECTORY} -path \*/error/* -type f -not -name "SS*" -not -name "AA*" -not -name "PQ*" -mmin +60 -print
I doubt, the ambiguous redirect error is because of multiple -not options that you've used. (Though I do not have a Unix system available, so I couldn't verify it).

Last edited by shivaa; 04-30-2013 at 06:46 AM.
 
Old 04-30-2013, 06:32 AM   #7
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 592

Rep: Reputation: 140Reputation: 140
Check if ${ERR0R_FILES} exists and else first create it. The find command works fine here.

Last edited by whizje; 04-30-2013 at 06:34 AM.
 
Old 04-30-2013, 08:39 AM   #8
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by whizje View Post
Check if ${ERR0R_FILES} exists and else first create it. The find command works fine here.
Its not necessory to file ${ERR0R_FILES} already exist. It will be created automatically. Both commands are running fine. So it seems some pb with OP's working shell.

@OP:
Can you once try following, without closing variable name in curly braces, as follow:
Code:
find $BASE_DIRECTORY -path \*/error/* -type f -not -name "SS*" -not -name "AA*" -not -name "PQ*" -mmin +60 -print >> $ERR0R_FILES

Last edited by shivaa; 04-30-2013 at 08:41 AM.
 
Old 04-30-2013, 10:52 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,251

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
My bad on my first point ... it just seemed there should be some and's or or's in between the not's. I am guessing this is somehow implied as an and in this case.

And yes shivaa pointed out my curious question correctly. Personally I would have just used single quotes as escaping gives me the yips.
 
Old 04-30-2013, 10:58 AM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
As was suggested by whizje, the "ambiguous redirect" error is very likely due to the unquoted variable ERROR_FILES containing embedded white space in its value. I can easily reproduce the behavior that way:
Code:
$ ERROR_FILES="bad files"
$ echo hello >>${ERROR_FILES}
bash: ${ERROR_FILES}: ambiguous redirect
$
 
1 members found this post helpful.
Old 04-30-2013, 04:06 PM   #11
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 592

Rep: Reputation: 140Reputation: 140
Quote:
Its not necessary to file ${ERR0R_FILES} already exist. It will be created automatically. Both commands are running fine. So it seems some pb with OP's working shell.
I should be more precise in my writing. I meant check if ERROR_FILES contains a value and is not empty.
 
Old 05-02-2013, 11:54 PM   #12
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
@grail

I don't think so there is anything missing between -not -name "PQRS*" I believe this is the syntax, anything wrong here?
 
Old 05-03-2013, 05:19 AM   #13
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
@whizje

I did try " around the variable name but that didn't worked not sure why.
 
Old 05-03-2013, 05:22 AM   #14
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
@shivaa

Why you suggest the original quote without curly brace? normally we use variable in dollar with curly braces right?

Please advise.

Thanks.
 
Old 05-03-2013, 05:40 AM   #15
sysmicuser
Member
 
Registered: Mar 2010
Posts: 332

Original Poster
Rep: Reputation: 0
Question

@shivaa

Quote:
You have just redirected the std error, but error is still there.
So if there is any error, forget about that error how should we capture it? I believe

Code:
2>&1 | tee -a ${LOG_FILE}
Captures pretty much any error? I want to capture any error and end the script there and there itself instead of proceeding further.
 
  


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
[SOLVED] Redirection question ZaphoidPA Linux - Networking 2 01-14-2013 02:08 PM
redirection question penguinlover2 Linux - Newbie 2 10-09-2012 08:27 AM
Redirection question mortonmorton Linux - Newbie 7 10-07-2009 01:55 PM
Redirection question ShaqDiesel Linux - General 3 01-06-2009 06:41 PM
Redirection question... Zeracles *BSD 0 02-21-2004 12:11 PM


All times are GMT -5. The time now is 11:00 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