LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-16-2014, 05:28 AM   #1
anand1
LQ Newbie
 
Registered: Oct 2014
Posts: 2

Rep: Reputation: Disabled
Smile ambiguous redirect


Hi Friends,

I am a beginner to shell script.I have run the shell script in tcsh shell.

In my shell script code,I am trying to redirect output to a file.
But getting ambiguous redirect

Code:
su -c "exit" - prime310 > pnoutput.txt 2>&1
2>&1 redirect stdout and stderr to pnoutput.txt.(correct me if i am wrong)

I also tried in bash shell. but same ambiguous redirect error came.

I have searched in Google. but not able to
find clear solution.

Please help me to resolve this issue.


Regards,
Anand

Last edited by anand1; 10-16-2014 at 07:32 AM. Reason: explaining issue little bit more
 
Old 10-16-2014, 06:14 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
would be nice to see more, that looks not enough to find the reason.
please use [code]here comes your code[/code] to keep formatting.
You can put set -xv at the beginning of your script to see what's happening
 
Old 10-17-2014, 04:55 AM   #3
mithun119
LQ Newbie
 
Registered: Aug 2014
Posts: 16

Rep: Reputation: Disabled
Hi Anand,

TCSH stdout/stderr redirection happens in a different way.

BASH:
[root@vmtest02 lab]# su -c "date" kummit01 > /tmp/mitx 2>&1
[root@vmtest02 lab]# cat /tmp/mitx
Fri Oct 17 04:44:51 CDT 2014


TCSH:
STDOUT redirection:
[root@vmtest02 lab]# su -c "date" kummit01 >& /tmp/mitx
[root@vmtest02 lab]# cat /tmp/mitx
Fri Oct 17 04:52:12 CDT 2014

STDERR redirection:
[root@vmtest02 lab]# su -c "dat" kummit01 > & /tmp/mitx
[root@vmtest02 lab]# cat /tmp/mitx
bash: dat: command not found
[root@vmtest02 lab]#
 
Old 10-27-2014, 07:42 AM   #4
anand1
LQ Newbie
 
Registered: Oct 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi Mithun,

Thanks for the reply.

After your suggestion, I have modified the code as below in the sh file.(I am using TCSH shell).

<code>
su -c "exit" - prime310 >& /export/home/prime310/pnoutput.txt
cat pnoutput.txt
</code>

and ran the sh file as
sh filename.sh
i.e
<code>
sh pn_failure_detection.sh
</code>

but sh file is not execute successfully and the shell got struck. I forcefully stop the shell buy pressing ctrl+x.
 
Old 10-27-2014, 07:58 AM   #5
mithun119
LQ Newbie
 
Registered: Aug 2014
Posts: 16

Rep: Reputation: Disabled
This part of your command is perfectly fine. It works as desired on bash or tcsh.
su -c "exit" - prime310 >& /export/home/prime310/pnoutput.txt && cat pnoutput.txt --> in ideal case is not expected to give any output if the id exists

See eg. below for stdout and stderr redirected to the output file.
[root@vmtest02 lab]# su -c "exit" - test1 >& /tmp/test.^Ct
[root@vmtest02 lab]# cat /tmp/test.out
[root@vmtest02 lab]# su -c "exit" - test123 >& /tmp/test.out
[root@vmtest02 lab]# cat /tmp/test.out
su: user test123 does not exist


What else is going into your <code> sections needs to be scrutinized. What exactly are you trying to achieve. We require more info to tell you why your script slipped into loops.
 
  


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] ambiguous redirect error mia_tech Linux - General 4 03-13-2014 08:45 AM
ambiguous redirect error upendra_35 Linux - Newbie 3 12-12-2012 07:51 PM
[SOLVED] bash ambiguous redirect wakatana Programming 2 03-09-2011 09:35 AM
Ambiguous Redirect Error AMMullan Linux - General 1 10-01-2003 08:39 PM
ambiguous redirect? cuss Linux - General 4 03-06-2003 10:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05: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
Open Source Consulting | Domain Registration