|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
#1 |
Where there's a will, I want to be in it.
|
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 |
![]() |
![]() |
![]() |
#2 |
Vagabond
|
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? |
![]() |
![]() |
![]() |
#3 |
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 |
![]() |
![]() |
![]() |
#4 |
Where there's a will, I want to be in it.
|
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 |
![]() |
![]() |
![]() |
#5 | |
Shut up brain, or I'll stab you with a Q-tip!
Join Date: Aug 2003
Posts: 114
|
Quote:
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.. |
|
![]() |
![]() |
![]() |
#6 |
Where there's a will, I want to be in it.
|
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 |
![]() |
![]() |
![]() |
#7 |
Where there's a will, I want to be in it.
|
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 |
![]() |
![]() |
![]() |
#8 |
Vagabond
|
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". |
![]() |
![]() |
![]() |
#9 |
Where there's a will, I want to be in it.
|
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 |
![]() |
![]() |
![]() |
#10 |
Vagabond
|
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. |
![]() |
![]() |
![]() |
#11 |
Where there's a will, I want to be in it.
|
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 |
![]() |
![]() |
![]() |
#12 | |
Shut up brain, or I'll stab you with a Q-tip!
Join Date: Aug 2003
Posts: 114
|
Quote:
for var in `cat domains.txt` do echo $var done More info here: http://unix.about.com/library/course/blshscript-l7a.htm |
|
![]() |
![]() |
![]() |
#13 |
Vagabond
|
Another good guide is Advanced Bash-Scripting Guide
![]() |
![]() |
![]() |
![]() |
#14 |
Where there's a will, I want to be in it.
|
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 |
![]() |
![]() |
![]() |
#15 |
The only guys who wear Hawaiian shirts are gay guys and big fat party animals
|
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 |
![]() |
![]() |
![]() |
|
|