Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   shell script error msg (http://www.greenguysboard.com/board/showthread.php?t=9144)


The line it's referencing is

printf "
" >> $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
spacemanspiff 2004-07-10 07:23 AM

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 `"
SitePages HitUniqs

swedguy 2004-07-10 08:50 AM

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?

";

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 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 2004-07-11 02:19 AM

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 "
$sst

spacemanspiff 2004-07-11 09:45 AM

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 "
Site Stats
"date"
" > $sst
printf "\n" >> $sst
printf "" >> $sst
printf "\n" >> $sst
while read servername

Line 14 was causing the same error, so I commented it just to get past that line
SitePages HitUniqsAltaVistaAOLGoogleYahooAllEngines

airdick 2004-07-11 11:44 AM

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.

spacemanspiff 2004-07-13 06:13 AM

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.

spacemanspiff 2004-07-13 07:29 AM

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.

swedguy 2004-07-13 10:00 AM

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".

spacemanspiff 2004-07-13 10:13 AM

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

swedguy 2004-07-13 11:14 AM

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.

spacemanspiff 2004-07-13 01:01 PM

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.

airdick 2004-07-13 11:16 PM

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

swedguy 2004-07-14 06:21 AM

Another good guide is Advanced Bash-Scripting Guide :)

spacemanspiff 2004-07-14 08:12 AM

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

raymor 2004-08-10 12:58 AM

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


All times are GMT -4. The time now is 12:54 PM.

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