Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2004-07-10, 07:23 AM   #1
spacemanspiff
Where there's a will, I want to be in it.
 
spacemanspiff's Avatar
 
Join Date: Aug 2003
Location: Looz-e-anna
Posts: 1,015
Send a message via ICQ to spacemanspiff
shell script error msg

I'm trying to run a shell script on a Linux system and I keep getting an error message:

"Syntax error near unexpected token `"<tr><t'

The line it's referencing is

printf "<tr><td>Site</td><td align='right'>Pages Hit</td><td align='right'>Uniqs</td>" >> $sst

What in the heck is an unexpected token? The script works fine on a unix box. I've struck out trying to find info about it on google.

Thanks
SS
__________________
Submit your free sites to Free Sex Pics
spacemanspiff is offline   Reply With Quote
Old 2004-07-10, 08:50 AM   #2
swedguy
Vagabond
 
swedguy's Avatar
 
Join Date: Aug 2003
Posts: 2,374
Send a message via ICQ to swedguy
What type of shell script is it? sh, bash, csh,.... (you can see it on the first line of the script)?

Can you post what the script looks like where you get the error and 4-5 lines above that line?
swedguy is offline   Reply With Quote
Old 2004-07-11, 02:19 AM   #3
Bunnyhop
Lord help me, I'm just not that bright
 
Join Date: Jun 2004
Posts: 106
To me it sounds like you're missing a double quotion mark (")...maybe at the end of a line?

ex

$sst = "This is my site";
printf "Hello world, ;
printf "<tr><td>$sst</td></tr>";

You see in the second line there's no " at the end...so the script actually thinks the second line is to display

Hello world,;
printf

Now on line 3 the first quotation mark is considered the end of line for line #2...which then makes the script assume the quote is done and looks for new commands to process...in this case it finds <tr> as the next supposed command...which is a bad command and causes an error.

If you want to provide the previous five lines of your script I probably can locate the quote problem
Bunnyhop is offline   Reply With Quote
Old 2004-07-11, 09:45 AM   #4
spacemanspiff
Where there's a will, I want to be in it.
 
spacemanspiff's Avatar
 
Join Date: Aug 2003
Location: Looz-e-anna
Posts: 1,015
Send a message via ICQ to spacemanspiff
Here's the first 18 lines:

#!/bin/sh
serverlist=$1
sst=/web/sites/sitestatstable/index.html"
echo > test
gt=0
at=0
yt=0
aolt=0
aet=0
sitecount=0
totaluniqs=0
totalpages=0
bgcolor="#999999"
#echo "<center>Site Stats<br>"date"<br><center>" > $sst
printf "<table cellspacing=0 cellpadding=4 width='100%%'>\n" >> $sst
printf "<tr><td>Site</td><td align='right'>Pages Hit</td><td align='right'>Uniqs</td>" >> $sst
printf "<td align='right'>AltaVista</td><td align='right'>AOL</td><td align='right'>Google</td><td align='right'>Yahoo</td><td align='right'>AllEngines</td></tr>\n" >> $sst
while read servername

Line 14 was causing the same error, so I commented it just to get past that line
__________________
Submit your free sites to Free Sex Pics
spacemanspiff is offline   Reply With Quote
Old 2004-07-11, 11:44 AM   #5
airdick
Shut up brain, or I'll stab you with a Q-tip!
 
Join Date: Aug 2003
Posts: 114
Quote:
Originally posted by spacemanspiff

sst=/web/sites/sitestatstable/index.html"
Bunnyhop is right.
There is an unmatched " on that line. I think that's where your problem is. Try this instead:

sst="/web/sites/sitestatstable/index.html"

The script doesn't report an error until it matches that stray " with the next one it finds way down on line 14 and tries to figure out what to do next.

Last edited by airdick; 2004-07-11 at 11:48 AM..
airdick is offline   Reply With Quote
Old 2004-07-13, 06:13 AM   #6
spacemanspiff
Where there's a will, I want to be in it.
 
spacemanspiff's Avatar
 
Join Date: Aug 2003
Location: Looz-e-anna
Posts: 1,015
Send a message via ICQ to spacemanspiff
Sheesh, that's just increcible. I don't understand how I could miss something so obvious, but I do it a lot. Tunnelvision I guess.

Thanks for the help guys.
__________________
Submit your free sites to Free Sex Pics
spacemanspiff is offline   Reply With Quote
Old 2004-07-13, 07:29 AM   #7
spacemanspiff
Where there's a will, I want to be in it.
 
spacemanspiff's Avatar
 
Join Date: Aug 2003
Location: Looz-e-anna
Posts: 1,015
Send a message via ICQ to spacemanspiff
Ok, next stupid question. The script gets a list of domains to search for in the raw log files from a text file called domains.txt. The command is something like:

analyzelogs.sh domains.txt

What I don't understand is why the names change. In the second line, the first input variable (did I say that right?), $1 is assigned the name "serverlist" yet when the time comes for the while loop, which scans the logs looking for each individual domain, it seems to change to "servername". Shouldn't those be the same?

serverlist = $1
while read serverlist
do some stuff


In case anyone is wondering, this scipt was written by a former tech, and works great on a dedicated server with a single raw log file. I'm trying to modify it for use on a virtual account where I have access to the raw logs, but each domain has it's own file.

I seem to be getting stuck in an endless loop. I pared the thing down to just try and read the domains.txt file and print out the names of the domains on the list with no more processing.

#!/bin/bash
serverlist=$1
sst="/web/sites/sitestatstable/index.html"
printf "Analyzing the Log Files...one moment please"

while read servername

do
printf $servername

if [ -f /var/log/apache/$servername ]
then
printf "Y"

else
printf "N"

fi

done




No luck.
__________________
Submit your free sites to Free Sex Pics
spacemanspiff is offline   Reply With Quote
Old 2004-07-13, 10:00 AM   #8
swedguy
Vagabond
 
swedguy's Avatar
 
Join Date: Aug 2003
Posts: 2,374
Send a message via ICQ to swedguy
If you did paste the whole script and there's nothing between these two lines...


printf "Analyzing the Log Files...one moment please"

while read servername


then "servername" should be "serverlist".
swedguy is offline   Reply With Quote
Old 2004-07-13, 10:13 AM   #9
spacemanspiff
Where there's a will, I want to be in it.
 
spacemanspiff's Avatar
 
Join Date: Aug 2003
Location: Looz-e-anna
Posts: 1,015
Send a message via ICQ to spacemanspiff
I tried it that way swedguy. Makes perfect sense to me. It prints the little greeting message, then just hangs up.

What I pasted is the entire test script i'm trying to run, just to see why i'm not getting paste that point on the real script.

I'll try it again though. Ya never know. Any other ideas/thoughts would be appreciated. Maybe a problem reading the text file with the list of domains? (there's only one on there right now).

Thanks again
__________________
Submit your free sites to Free Sex Pics
spacemanspiff is offline   Reply With Quote
Old 2004-07-13, 11:14 AM   #10
swedguy
Vagabond
 
swedguy's Avatar
 
Join Date: Aug 2003
Posts: 2,374
Send a message via ICQ to swedguy
ahhh, I was looking at the wrong thing.

"read" waits for you to type something.

while read servername


If you start the program and then type "domain.com", it will assign domain.com to the variable "servername" and check if /var/log/apache/domain.com is an ordinary file.
swedguy is offline   Reply With Quote
Old 2004-07-13, 01:01 PM   #11
spacemanspiff
Where there's a will, I want to be in it.
 
spacemanspiff's Avatar
 
Join Date: Aug 2003
Location: Looz-e-anna
Posts: 1,015
Send a message via ICQ to spacemanspiff
That makes sense. It's not stuck in an endless loop, it's waiting for some input.

So how do I tell it to read from a file, one line at a time and then "do" something with each line. On the version of the script that's working, I don't have to enter any input. That's all done from the crontab, which starts a small script that stops the server, rotates the logs, then calls another script to analyze the logs, with the inputs specified by the small script

./analyzelogs domains.txt

with all the "domain.coms" listed in the .txt file.
__________________
Submit your free sites to Free Sex Pics
spacemanspiff is offline   Reply With Quote
Old 2004-07-13, 11:16 PM   #12
airdick
Shut up brain, or I'll stab you with a Q-tip!
 
Join Date: Aug 2003
Posts: 114
Quote:
Originally posted by spacemanspiff

So how do I tell it to read from a file, one line at a time and then "do" something with each line.
Here is an example of a bourne shell "for loop" that does something with each item in domains.txt:

for var in `cat domains.txt`
do
echo $var
done

More info here:
http://unix.about.com/library/course/blshscript-l7a.htm
airdick is offline   Reply With Quote
Old 2004-07-14, 06:21 AM   #13
swedguy
Vagabond
 
swedguy's Avatar
 
Join Date: Aug 2003
Posts: 2,374
Send a message via ICQ to swedguy
Another good guide is Advanced Bash-Scripting Guide
swedguy is offline   Reply With Quote
Old 2004-07-14, 08:12 AM   #14
spacemanspiff
Where there's a will, I want to be in it.
 
spacemanspiff's Avatar
 
Join Date: Aug 2003
Location: Looz-e-anna
Posts: 1,015
Send a message via ICQ to spacemanspiff
Great info guys. Very much appreciated.

I've got a ton of stuff bookmarked for perl, but I was having trouble finding shell scripting sites. Don't know why.

Thanks again
SS
__________________
Submit your free sites to Free Sex Pics
spacemanspiff is offline   Reply With Quote
Old 2004-08-10, 12:58 AM   #15
raymor
The only guys who wear Hawaiian shirts are gay guys and big fat party animals
 
Join Date: Jan 2004
Posts: 178
Send a message via ICQ to raymor
rather than dumping the whole file as
arguments to a for loop like this:
for line in `cat $filename`
It would be better to wkeep the while loop:
while read servername
and redirect the standard input of the script when you call it:
thescript.sh <domainlist.txt
__________________
Ray Morris
support@bettercgi.com
Strongbox/Throttlebox & more
TXDPS #A14012
raymor is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:33 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc