Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange redirect problem

Status
Not open for further replies.

kharybdis

Technical User
Mar 3, 2001
9
US
I'm using a basic bash script to generate an HTML page. It's just using echo, since only one thing needs to change. That one thing is a variable $extip, which = my current IP.
I've used this technique a bunch of times and it's worked just fine, but now I have a strange problem. Here's the pertinent script:

#!/bin/bash
#
extip="`/sbin/ifconfig eth1 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"
echo &quot;<HTML>&quot;
echo &quot;<HEAD>&quot;
echo &quot;<TITLE>n8shome</TITLE>&quot;
echo '<SCRIPT LANGUAGE=&quot;JavaScript&quot;><-- setTimeout (&quot;changePage()&quot;, 3000); function changePage() { if (self.parent.frames.length != 0) self.parent.location=&quot;echo $extip
echo &quot;\&quot;;}//--></SCRIPT>'
echo &quot;</HEAD>&quot;

Now when I run this shell script, the HTML comes out just fine except for one thing. Notice the JavaScript line in the code above, specifically the $extip variable. Now here's how that same line comes out:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
setTimeout (&quot;changePage()&quot;, 0)
function changePage() {
if (self.parent.frames.length != 0)
self.parent.location=&quot;http://
xxx.xxx.xxx.xxx^M
&quot;;}//--></SCRIPT>

For some reason, suddenly I have an extra ^M behind the IP. It screws up the function of the script itself. I'm stumped. I tried to keep everything simple so as to avoid strange errors, but that's exactly what I got. Although I can appreciate true irony, I'd much rather see it in a Greek tragedy than in my code.

I have tried to use sed to get it out:

sed &quot;s/^M//g&quot; < index.html > index.new

and a couple of variations, using '^M', `^M`, and \^M, with no effect.

Details:
Mandrake 7.2
Bash shell
x86 platform
AMD K6/380

Again, I'm currently using the exact same technique for importing my current IP in about 6 different scripts, four of which are generating HTML the same way. It only goofs up when I try to echo it out while inside that JavaScript line. *shrug*

Thanks in advance, even if you can't make a suggestion I appreciate you reading this long message.

nathan
 
The only thing I notice in your shell script is some places you use echo&quot; &quot; and other
places you used echo ' ' and if on a seperate line situation where as the echo statement is carried on to the line below with out another echo you will need the shell
continue line statement function which i think is \ (backslash).

Might want to try also using perl for such things as striping the ^M which is the following line.

perl -ple 's/\r//g' < (filename)

I hope I wrote that correctly for you!
Hope this helps
Maxit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top