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 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 |
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 |
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]# |
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. |
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. |
All times are GMT -5. The time now is 01:40 AM. |