Unix Shell - OT? writing a script and messed up my system somehow

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2005 > OT? writing a script and messed up my system somehow





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author OT? writing a script and messed up my system somehow
Ben

2005-03-24, 2:54 am

This is a little off topic because it pertains to my system, BUT I did
it while trying to write a shell script so hopefully somebody else may
have seen something similar to this previosly. I tried posting this
already in a more pertinent group to no avail, thus, headed back to my
favorite group to learn from...so here goes:
first, background. My shell is tcsh. I was writing a script in csh (I'm
learning PERL now to get out of blasted csh which was the only shell I
knew). Anyway, I was writing a script to automatically generate some
html and in doing so I was echoing some unusual characters like <, >,
and : to a file. I didn't esacpe them at first (oops) and now, every
time I try to execute any of my scripts I get an error message:

Missing name for redirect.

I get the same error message upon logon (or startup of new xterm) and my
.tcshrc doesn't source. However, there is no problem with my .tcshrc
because I compared it to an old backed up version and it was identical.
further, I hadn't modified .tcshrc in quite some time. Also unusual, I
don't get any error messages if I "source" the same scripts. Thus, in
short, for a script called foo if I type

$ foo
I get
$ Missing name for redirect.

If I type
$ source foo
the script works fine. This applies to any script, not just the one I
was working on (which I'm not touching again till I, or someone, figures
out what I did). Other commands like ls,xpdf,mozilla, etc work fine. Its
like somethings wrong with the shell IO but I can't figure out what. Any
ideas?

Ben


Ben

2005-03-24, 2:54 am

Ben wrote:
> This is a little off topic because it pertains to my system, BUT I did
> it while trying to write a shell script so hopefully somebody else may
> have seen something similar to this previosly. I tried posting this
> already in a more pertinent group to no avail, thus, headed back to my
> favorite group to learn from...so here goes:
> first, background. My shell is tcsh. I was writing a script in csh (I'm
> learning PERL now to get out of blasted csh which was the only shell I
> knew). Anyway, I was writing a script to automatically generate some
> html and in doing so I was echoing some unusual characters like <, >,
> and : to a file. I didn't esacpe them at first (oops) and now, every
> time I try to execute any of my scripts I get an error message:
>
> Missing name for redirect.
>
> I get the same error message upon logon (or startup of new xterm) and my
> .tcshrc doesn't source. However, there is no problem with my .tcshrc
> because I compared it to an old backed up version and it was identical.
> further, I hadn't modified .tcshrc in quite some time. Also unusual, I
> don't get any error messages if I "source" the same scripts. Thus, in
> short, for a script called foo if I type
>
> $ foo
> I get
> $ Missing name for redirect.
>
> If I type
> $ source foo
> the script works fine. This applies to any script, not just the one I
> was working on (which I'm not touching again till I, or someone, figures
> out what I did). Other commands like ls,xpdf,mozilla, etc work fine. Its
> like somethings wrong with the shell IO but I can't figure out what. Any
> ideas?
>
> Ben
>
>

I've now noticed that when I try to execute a simple script foo:

#!/bin/csh -f
echo hi

it works. But if I replace the -f with a -V I get the following error,
the last part of which follows (I assume the < /tr > ; is somehow
messing things up because its looks like something I was doing in my
original script that messed things up but I don't know why its there).

set sourced=0
foreach file ( /etc/sysconfig/i18n $HOME/.i18n )
if ( -f $file ) then
eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
\1 \2|g' | sed 's|$|;|'`
setenv LANG "en_US.UTF-8" ; setenv SUPPORTED "en_US.UTF-8:en_US:en" ;
setenv SYSFONT "latarcyrheb-sun16" ;
endif
set sourced=1
end
if ( -f $file ) then
eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
\1 \2|g' | sed 's|$|;|'`
< /tr > ;
Missing name for redirect.


I've also just found out that if I comment out EVERY line in my .tcshrc
file I still get the error. So saying -f at the top of any script shows
no error, but having no input in .tcshrc (commented out lines) gives the
error. So somehow calling .tcshrc is giving this error.
Icarus Sparry

2005-03-24, 2:54 am

On Thu, 24 Mar 2005 00:22:56 -0500, Ben wrote:
[vbcol=seagreen]
> Ben wrote:

[Lots more useful information, snipped]

This is an excellent pair of posts, telling us lots of things. If only
more posts asking for help were this informative.

If I understand it correctly, tThere are 3 cases.
1) programs written in 'csh/tcsh', which start '#!/bin/csh -f'
2) programs written in csh/tcsh, which start without the '-f'
3) programs written in something else.
Type 1 and 3 work, but type 2 don't.
The big difference is that type 2 go through the normal tcsh/csh startup,
so that is the place to look. If it were me, I would type 'tcsh -XV',
which will show you the startup commands being executed, and will give you
some idea of what the command is that is causing you problems. In order to
find where the problem is, I would run 'strace -eopen tcsh -XV' to see the
files being opened. If your shell startup files do not include other
files, then the last file opened before you get the 'redirect' error will
be the faulty one. If they do source others, then you have a little more
detective work to do.

I would guess that your error is due to ~/.history (or whatever the value
of 'histfile' is set to), and you should just delete it.
Ben

2005-03-24, 2:54 am

Icarus Sparry wrote:
> On Thu, 24 Mar 2005 00:22:56 -0500, Ben wrote:
>
>
>
>
> [Lots more useful information, snipped]
>
> This is an excellent pair of posts, telling us lots of things. If only
> more posts asking for help were this informative.
>
> If I understand it correctly, tThere are 3 cases.
> 1) programs written in 'csh/tcsh', which start '#!/bin/csh -f'
> 2) programs written in csh/tcsh, which start without the '-f'
> 3) programs written in something else.
> Type 1 and 3 work, but type 2 don't.
> The big difference is that type 2 go through the normal tcsh/csh startup,
> so that is the place to look. If it were me, I would type 'tcsh -XV',
> which will show you the startup commands being executed, and will give you
> some idea of what the command is that is causing you problems. In order to
> find where the problem is, I would run 'strace -eopen tcsh -XV' to see the
> files being opened. If your shell startup files do not include other
> files, then the last file opened before you get the 'redirect' error will
> be the faulty one. If they do source others, then you have a little more
> detective work to do.
>
> I would guess that your error is due to ~/.history (or whatever the value
> of 'histfile' is set to), and you should just delete it.


I ran your suggested strace line and got the following output, with the
beginning snipped:

[snip]
endif
endif
set sourced=1
set sourced=1
end
end
if ( -f $file ) then
if ( -f /home/ben/.i18n ) then
eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
\1 \2|g'| sed 's|$|;|'`
eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
\1 \2|g'| sed 's|$|;|'`
grep -v ^[:blank:]*# /home/ben/.i18n
sed s|\([^=]*\)=\([^=]*\)|setenv \1 \2|g
sed s|$|;|
--- SIGCHLD (Child exited) @ 0 (0) ---
< /tr > ;
Missing name for redirect.
open("/etc/localtime", O_RDONLY) = 3


I get the same error message just typing 'tcsh -XV' and hitting enter. I
suspect the < /tr > ; is the problem but I don't know why that is
executing or where it could be from. I ran the above strace command with
every line in my .tcshrc commented out. The same error appears when I
execute foo (foo snipped in original post). I don't know where its
getting this < /tr > ; from. Anything else I can provide that may give
anyone more ideas?

I did find one other thing out, if I change the first line of foo to be
#!/bin/bash I do NOT get an error message (but maybe you already assumed
this). I'm headed to bed now but will check again in the morning. FYI,
removing my history file didn't help. Thanks, I look forward to anyone's
thoughts/ideas.
Bruce Barnett

2005-03-24, 7:53 am

Ben <none@none.com> writes:

> --- SIGCHLD (Child exited) @ 0 (0) ---
> < /tr > ;
> Missing name for redirect.



I'm not sure I understand your script.

You gave us

if ( -f $file ) then
eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
\1 \2|g' | sed 's|$|;|'`
< /tr > ;
Missing name for redirect.

and I can't tell where your script ends.
I do see
eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
\1 \2|g' | sed 's|$|;|'`

which is TWO LINES in your posting. csh cannot have strings longer
than one line. But that may be your news reader.

What exactly is

< /tr > ;

is this a command?

If it is, you are sending output to a file with no name.
And if I execute that line, I get the same error.

Generally it's a bad idea to have c shell scripts that are missing "-f" on the first line.

I can shorten that sentence even further. :-)

If you need something from your startup scripts, put it in a separate
file and source it, or copy/paste it.


--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Ben

2005-03-24, 7:53 am

Bruce Barnett wrote:
> Ben <none@none.com> writes:
>
>
>
>
>
> I'm not sure I understand your script.
>
> You gave us
>
> if ( -f $file ) then
> eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
> \1 \2|g' | sed 's|$|;|'`
> < /tr > ;
> Missing name for redirect.
>
> and I can't tell where your script ends.
> I do see
> eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
> \1 \2|g' | sed 's|$|;|'`
>
> which is TWO LINES in your posting. csh cannot have strings longer
> than one line. But that may be your news reader.
>
> What exactly is
>
> < /tr > ;
>
> is this a command?
>
> If it is, you are sending output to a file with no name.
> And if I execute that line, I get the same error.
>
> Generally it's a bad idea to have c shell scripts that are missing "-f" on the first line.
>
> I can shorten that sentence even further. :-)
>
> If you need something from your startup scripts, put it in a separate
> file and source it, or copy/paste it.
>
>

I guess I'm not clear. This is NOT a script. Its just the output I get
when I run a 'strace -eopen tcsh -XV' and hit enter (as suggested by
Icarus a few lines above). NO script. So somehow this stuff (error
causing code) has gotten into some file that I didn't even think I was
editing (on purpose anyway) that is executed on any script startup,
..tcshrc, .login, etc. but I don't seem to see anything. Hope that helps.












Icarus Sparry

2005-03-24, 5:52 pm

On Thu, 24 Mar 2005 08:54:54 -0500, Ben wrote:

> I guess I'm not clear. This is NOT a script. Its just the output I get
> when I run a 'strace -eopen tcsh -XV' and hit enter (as suggested by
> Icarus a few lines above). NO script. So somehow this stuff (error
> causing code) has gotten into some file that I didn't even think I was
> editing (on purpose anyway) that is executed on any script startup,
> .tcshrc, .login, etc. but I don't seem to see anything. Hope that helps.


Thanks, it was clear to me. What you didn't do was give enough of the
output. What would have been interesting is the line like

open("/etc/localtime", O_RDONLY) = 3

but with a different filename that happened BEFORE the error. tcsh is
reading some files when it is started without the '-f', and one of these
has the incorrect message in it. It might be the file '/home/ben/.i18n'
being called in the 'eval'. Try

mv /home/ben/.i18n /home/bin/old.i18n

and see if it clears up your problem.
Ben

2005-03-24, 5:52 pm

Icarus Sparry wrote:
> On Thu, 24 Mar 2005 08:54:54 -0500, Ben wrote:
>
>
>
>
> Thanks, it was clear to me. What you didn't do was give enough of the
> output. What would have been interesting is the line like
>
> open("/etc/localtime", O_RDONLY) = 3
>
> but with a different filename that happened BEFORE the error. tcsh is
> reading some files when it is started without the '-f', and one of these
> has the incorrect message in it. It might be the file '/home/ben/.i18n'
> being called in the 'eval'. Try
>
> mv /home/ben/.i18n /home/bin/old.i18n
>
> and see if it clears up your problem.


I just got home from work and was anxious to get his resolved and Yes!
This was it exactly. Removing ".i18n" solved my problem. I guess now for
me the next step is to learn why ALL files get processed during start up
rather than just a certain set such as .login, .tcshrc, etc. The i18n
file only 4 (non space) characters, I'm sure I know what your guess is:

< /tr >

Thanks for everyone's help. Wow.
Icarus Sparry

2005-03-24, 5:52 pm

On 2005-03-24, Ben <none@none.com> wrote:
> Icarus Sparry wrote:
>
> I just got home from work and was anxious to get his resolved and Yes!
> This was it exactly. Removing ".i18n" solved my problem. I guess now for
> me the next step is to learn why ALL files get processed during start up
> rather than just a certain set such as .login, .tcshrc, etc.


Only certain files are processed. The problem is that one of the files
which is processed has something like the following in it

if ( -f $file ) then
eval `grep -v '^[:blank:]*#' $file | \
sed 's|\([^=]*\)=\([^=]*\)|setenv \1 \2|g'| sed 's|$|;|'`
endif

and at the time it is processed the value of $file is /home/ben/.i18n

The command edits the contents of $file, and then evaluates it.

The command appears to be attempting to convert a set of assignments
from 'sh' to 'csh' syntax in the file. (There are better ways of doing
it which do not involve 3 processes).

If you just run 'strace -eopen tcsh' you will get less output, but it
will be more obvious which files are being read. It is possible that
a file is being read using 'source' which reads the file with the lines
in it.

> Thanks for everyone's help. Wow.


You are welcome. Your initial problem reports made it fairly easy! May
I suggest that you abandon tcsh, and switch to bash/zsh/ksh? Most people
agree that they are better choices than tcsh.

Icarus Sparry

2005-03-28, 6:18 pm

On Thu, 24 Mar 2005 00:22:56 -0500, Ben wrote:
[vbcol=seagreen]
> Ben wrote:

[Lots more useful information, snipped]

This is an excellent pair of posts, telling us lots of things. If only
more posts asking for help were this informative.

If I understand it correctly, tThere are 3 cases.
1) programs written in 'csh/tcsh', which start '#!/bin/csh -f'
2) programs written in csh/tcsh, which start without the '-f'
3) programs written in something else.
Type 1 and 3 work, but type 2 don't.
The big difference is that type 2 go through the normal tcsh/csh startup,
so that is the place to look. If it were me, I would type 'tcsh -XV',
which will show you the startup commands being executed, and will give you
some idea of what the command is that is causing you problems. In order to
find where the problem is, I would run 'strace -eopen tcsh -XV' to see the
files being opened. If your shell startup files do not include other
files, then the last file opened before you get the 'redirect' error will
be the faulty one. If they do source others, then you have a little more
detective work to do.

I would guess that your error is due to ~/.history (or whatever the value
of 'histfile' is set to), and you should just delete it.
Ben

2005-03-28, 6:18 pm

Icarus Sparry wrote:
> On Thu, 24 Mar 2005 00:22:56 -0500, Ben wrote:
>
>
>
>
> [Lots more useful information, snipped]
>
> This is an excellent pair of posts, telling us lots of things. If only
> more posts asking for help were this informative.
>
> If I understand it correctly, tThere are 3 cases.
> 1) programs written in 'csh/tcsh', which start '#!/bin/csh -f'
> 2) programs written in csh/tcsh, which start without the '-f'
> 3) programs written in something else.
> Type 1 and 3 work, but type 2 don't.
> The big difference is that type 2 go through the normal tcsh/csh startup,
> so that is the place to look. If it were me, I would type 'tcsh -XV',
> which will show you the startup commands being executed, and will give you
> some idea of what the command is that is causing you problems. In order to
> find where the problem is, I would run 'strace -eopen tcsh -XV' to see the
> files being opened. If your shell startup files do not include other
> files, then the last file opened before you get the 'redirect' error will
> be the faulty one. If they do source others, then you have a little more
> detective work to do.
>
> I would guess that your error is due to ~/.history (or whatever the value
> of 'histfile' is set to), and you should just delete it.


I ran your suggested strace line and got the following output, with the
beginning snipped:

[snip]
endif
endif
set sourced=1
set sourced=1
end
end
if ( -f $file ) then
if ( -f /home/ben/.i18n ) then
eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
\1 \2|g'| sed 's|$|;|'`
eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
\1 \2|g'| sed 's|$|;|'`
grep -v ^[:blank:]*# /home/ben/.i18n
sed s|\([^=]*\)=\([^=]*\)|setenv \1 \2|g
sed s|$|;|
--- SIGCHLD (Child exited) @ 0 (0) ---
< /tr > ;
Missing name for redirect.
open("/etc/localtime", O_RDONLY) = 3


I get the same error message just typing 'tcsh -XV' and hitting enter. I
suspect the < /tr > ; is the problem but I don't know why that is
executing or where it could be from. I ran the above strace command with
every line in my .tcshrc commented out. The same error appears when I
execute foo (foo snipped in original post). I don't know where its
getting this < /tr > ; from. Anything else I can provide that may give
anyone more ideas?

I did find one other thing out, if I change the first line of foo to be
#!/bin/bash I do NOT get an error message (but maybe you already assumed
this). I'm headed to bed now but will check again in the morning. FYI,
removing my history file didn't help. Thanks, I look forward to anyone's
thoughts/ideas.
Ben

2005-03-29, 6:21 pm

Bruce Barnett wrote:
> Ben <none@none.com> writes:
>
>
>
>
>
> I'm not sure I understand your script.
>
> You gave us
>
> if ( -f $file ) then
> eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
> \1 \2|g' | sed 's|$|;|'`
> < /tr > ;
> Missing name for redirect.
>
> and I can't tell where your script ends.
> I do see
> eval `grep -v '^[:blank:]*#' $file | sed 's|\([^=]*\)=\([^=]*\)|setenv
> \1 \2|g' | sed 's|$|;|'`
>
> which is TWO LINES in your posting. csh cannot have strings longer
> than one line. But that may be your news reader.
>
> What exactly is
>
> < /tr > ;
>
> is this a command?
>
> If it is, you are sending output to a file with no name.
> And if I execute that line, I get the same error.
>
> Generally it's a bad idea to have c shell scripts that are missing "-f" on the first line.
>
> I can shorten that sentence even further. :-)
>
> If you need something from your startup scripts, put it in a separate
> file and source it, or copy/paste it.
>
>

I guess I'm not clear. This is NOT a script. Its just the output I get
when I run a 'strace -eopen tcsh -XV' and hit enter (as suggested by
Icarus a few lines above). NO script. So somehow this stuff (error
causing code) has gotten into some file that I didn't even think I was
editing (on purpose anyway) that is executed on any script startup,
..tcshrc, .login, etc. but I don't seem to see anything. Hope that helps.












Icarus Sparry

2005-03-29, 6:21 pm

On Thu, 24 Mar 2005 08:54:54 -0500, Ben wrote:

> I guess I'm not clear. This is NOT a script. Its just the output I get
> when I run a 'strace -eopen tcsh -XV' and hit enter (as suggested by
> Icarus a few lines above). NO script. So somehow this stuff (error
> causing code) has gotten into some file that I didn't even think I was
> editing (on purpose anyway) that is executed on any script startup,
> .tcshrc, .login, etc. but I don't seem to see anything. Hope that helps.


Thanks, it was clear to me. What you didn't do was give enough of the
output. What would have been interesting is the line like

open("/etc/localtime", O_RDONLY) = 3

but with a different filename that happened BEFORE the error. tcsh is
reading some files when it is started without the '-f', and one of these
has the incorrect message in it. It might be the file '/home/ben/.i18n'
being called in the 'eval'. Try

mv /home/ben/.i18n /home/bin/old.i18n

and see if it clears up your problem.
Icarus Sparry

2005-03-30, 7:55 am

On 2005-03-24, Ben <none@none.com> wrote:
> Icarus Sparry wrote:
>
> I just got home from work and was anxious to get his resolved and Yes!
> This was it exactly. Removing ".i18n" solved my problem. I guess now for
> me the next step is to learn why ALL files get processed during start up
> rather than just a certain set such as .login, .tcshrc, etc.


Only certain files are processed. The problem is that one of the files
which is processed has something like the following in it

if ( -f $file ) then
eval `grep -v '^[:blank:]*#' $file | \
sed 's|\([^=]*\)=\([^=]*\)|setenv \1 \2|g'| sed 's|$|;|'`
endif

and at the time it is processed the value of $file is /home/ben/.i18n

The command edits the contents of $file, and then evaluates it.

The command appears to be attempting to convert a set of assignments
from 'sh' to 'csh' syntax in the file. (There are better ways of doing
it which do not involve 3 processes).

If you just run 'strace -eopen tcsh' you will get less output, but it
will be more obvious which files are being read. It is possible that
a file is being read using 'source' which reads the file with the lines
in it.

> Thanks for everyone's help. Wow.


You are welcome. Your initial problem reports made it fairly easy! May
I suggest that you abandon tcsh, and switch to bash/zsh/ksh? Most people
agree that they are better choices than tcsh.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com