cancel
Showing results for 
Search instead for 
Did you mean: 

Shell Redirect error

 
SOLVED
Go to solution
pareshan
Regular Advisor

Shell Redirect error

Hi everyone, While I was trying to do

DATE=`date +"%Y%m%d_%H%M%S"`
STARTLOG=$TUXSTDDIR/start_$DATE.log
tmboot -y > $STARTLOG 2>&1



I got an error i.e. Ambiguous output redirect error. Here the first part is to boot the account so there is nothing wrong with that. I have defined the startlog also but I dint understand why I am having problem here.

I dint get what that error means. I will appreciate any help to make this right.

thanks alot
22 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: Shell Redirect error

Hi:

You're using the evil C-shell. Use a real shell (Poxix, Korn, or Bash). Since this is HP-UX, use the Posix shell --- '/usr/bin/sh'.

See this :

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

Regards!

...JRF...
pareshan
Regular Advisor

Re: Shell Redirect error

I think im using korn shell thought I have both ksh and csh. and i did something like that to be exact
#!/bin/ksh

DATE=`date +"%Y%m%d_%H%M%S"`
STARTLOG=$TUXSTDDIR/start_$DATE.log
tmboot -y > $STARTLOG 2>&1

doesnt that mean im using Korn shell?
and if lets suppose that is on csh how can I do something like that in csh? even complex way is fine just want to know how I can do it.

thanks
James R. Ferguson
Acclaimed Contributor

Re: Shell Redirect error

Hi:

Hmmm, so you did specify Korn (#!/bin/ksh).

I could reproduce your "ambiguous output redirect" thusly:

# cat ./myredir.csh
#!/usr/bin/csh
set STARTLOG=/tmp/something
lvlnboot -y > $STARTLOG 2>&1

...but not with:

# cat ./myredir.ksh
#!/usr/bin/ksh
STARTLOG=/tmp/something
lvlnboot -y > $STARTLOG 2>&1

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Shell Redirect error

Hi (again):

Are you running your script remotely, as with an 'remsh' command?

Regards!

...JRF...
pareshan
Regular Advisor

Re: Shell Redirect error

no im not using remsh or running command remotely.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Shell Redirect error

Hi (again):

If you do:

# su - someuser /myscript

...and 's default shell is the C-shell then regardless of the presence of the Korn shell interpreter line in 'myscript' you will produce the error.

Does this match what you are doing?

Regards!

...JRF...
Michael Mike Reaser
Valued Contributor

Re: Shell Redirect error

Please show us how you're invoking the script. First, issue the command

echo $SHELL

and show us the output. Next, issue the command you're using to invoke this script

myscript parm1 parm2 ... parmN

and show us the output from that.
There's no place like 127.0.0.1

HP-Server-Literate since 1979
pareshan
Regular Advisor

Re: Shell Redirect error

No that dint work. Instead of that I guess it will be helpful for me if there is any way to do similar to that in csh so that I can try that one if it works.

tmboot -y > $STARTLOG 2>&1
to me it looks like it should work on korn shell but its not so What im asking is how can we do like that in csh.
pareshan
Regular Advisor

Re: Shell Redirect error

I did the exactly you wanted
> echo $SHELL
/usr/bin/ksh
> set DATE=`date +"%Y%m%d_%H%M%S"`
> set STARTLOG=$TUXSTDDIR/start_$DATE.log
> tmboot -y > $STARTLOG 2>&1
Ambiguous output redirect.
>
here i dont need any parameters and all and I can put this in a file or I can run like this which shouldnt make any difference.
Michael Mike Reaser
Valued Contributor

Re: Shell Redirect error

OK, since we're sure you're in the Korn shell, issue the commands

whence tmboot
which tmboot
file $(whence tmboot)
file $(which tmboot)
ls -l $(whence tmboot)
ls -l $(which tmboot)

and, after youve' done the DATE= and STARTLOG= commands, add

echo $STARTLOG

and post the results.

I presume you've already got "TUXSTDDIR" set and epxorted in your shell environment? Otherwise, you'll be attempting to create a log file direectly under /, which is never a good idea.
There's no place like 127.0.0.1

HP-Server-Literate since 1979
pareshan
Regular Advisor

Re: Shell Redirect error

where tmboot
/usr/local/tux81/bin/tmboot
> which tmboot
/usr/local/tux81/bin/tmboot
> whence tmboot
whence: Command not found.

i dint get what you mean by
file $(whence tmboot)
file $(which tmboot)
ls -l $(whence tmboot)
ls -l $(which tmboot)

then i set DATE and STARTLOG as before

then i did
echo $STARTLOG
which gave
/tuxappl/tuxbug/rte_tlg/var/xmk/log/start_090107.log

and yeah I have already set TUXSTDDIR and exported

Re: Shell Redirect error

As JRF said, you are using the scummy C shell. It has that error: Ambiguous output redirect

To find your shell: ps -fp $$

>lets suppose that is on csh how can I do something like that in csh?

You don't even want to think about the scummy C shell. Find out why you aren't in a real shell.

>I didn't get what you mean by: file $(whence tmboot)

Type that exact command. But since you are in the scummy C shell, it will fail.

Note: The #! line must be the first line.

>What I'm asking is how can we do like that in scummy C shell:
scummy csh(1) says: command >& file

>Mike: issue the command: echo $SHELL

This isn't good enough, it only gives you your login shell.
One way of checking your shell is to give an invalid command:
abcdef
ksh: abcdef: not found
sh: abcdef: not found.
abcdef: Command not found. # scummy C shell
Bill Hassell
Honored Contributor

Re: Shell Redirect error

You can change your login shell with one command:

chsh pareshan /usr/bin/sh

Now logout and log back in again. Your active shell will be a sane POSIX shell.


Bill Hassell, sysadmin
pareshan
Regular Advisor

Re: Shell Redirect error

Dennis & James,

You guys are right. I am not in real ksh when I did what Dennis told I found im not in korn shell im in c shell.

> akdkjak
akdkjak: Command not found.
> file $(whence tmboot)
Illegal variable name.
and if i do same in another server in ksh it works as you said.

now I think I will use
command >& file

tmboot -y > & $STARTLOG
coz i dont think I am supposed to change the shell or so whtever works if gud for me... and its working

thanks alot guys
you guys are brilliant
pareshan
Regular Advisor

Re: Shell Redirect error

Now I have another problem when i do

tmboot -y > & filename

its says

ksh: syntax error: `&' unexpected

Im wondering why this is happenning.
James R. Ferguson
Acclaimed Contributor

Re: Shell Redirect error

Hi (again):

> tmboot -y > & filename

No, you want either:

tmboot -y > filename

or:

tmboot -y 2> filename

or:

tmboot -y filename 2>&1

The first redirects STDOUT to filename. The second redirects STDERR to filename. The third redirects both STDOUT and STDERR to filename (as you originally had).

The manpages for 'ksh' or for 'sh-poxix' describe redirection.

Regards!

...JRF...
pareshan
Regular Advisor

Re: Shell Redirect error

I think You dint get me. Thats what my problem is
tmboot -y > $STARTLOG 2>&1
--> ambigious output redirect
this dint work coz script is running in the server using c shell and thats why I changed to

tmboot -y >& filename now it says & unexpected. which I believe is the correct syntax for c shell. Im really conufused now whats going on here. there is no other way to put output of the command tmboot -y to that file $STARTLOG other than what we have discussed here before.


James R. Ferguson
Acclaimed Contributor

Re: Shell Redirect error

Hi (again) :

Oh, you need to run your script as a 'csh' (yuk!). Do this (thank Tom, [from the original link I cited] not me!):

cat .sillycsh
#!/usr/bin/csh
set LOG="/tmp/something_`(date '+%Y%m%d_%X')`"
sh -c "lvlnboot -y > ${LOG} 2>&1"
echo "see: ${LOG}"

...I used 'lvlnboot' since I don't have your executable :-)

Regards!

...JRF...
OldSchool
Honored Contributor

Re: Shell Redirect error

Re: Shell Redirect error

>tmboot -y > & filename

You shouldn't have a space: >&

>it says
ksh: syntax error: `&' unexpected

Now you are using a real shell. Please put the syntax back and remove all occurrences of the scummy C shell.

If you have a script the first line will indicate the interpreter:
#!/usr/bin/ksh
pareshan
Regular Advisor

Re: Shell Redirect error

OldSchool, this is somehow related to that one (wrapper script) but most of the things you told did work. I havent made it complete that why i dint close it or replied back yet thanks alot
pareshan
Regular Advisor

Re: Shell Redirect error

Thank all of you guys. I really appreciate the help.