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!

Need help with this script 1

Status
Not open for further replies.

trunky1

Technical User
Jun 12, 2009
6
Hi,

I have a small script I shall make running again... sadly the original programmer is gone long time ago, no chance to contact him, so hop you can help me (never seen AWK before).

its the line of in a CLI PHP script

awk '/"GET \/avs\/.*\.rm.* HTTP\/[1-9]\.[0-9]" 200/ {print $3,$7,$4,$11}' $LOGDIR/access_log >> $DOWNLOAD_FILE.unsorted

where the interpreter say
awk: cmd. line:1: $3,$7,$4,$11}
awk: cmd. line:1: ^ syntax error
script.php: line 26: syntax error near unexpected token `newline'
script.php: line 26: `HTTP\/[1-9]\[0-9]" 200 {print $3,$7,$4,$11}' >>'


Hope someone can help me?

trunky
 
The line you posted seems like shell script, not php.
 
Ok guys, thanks for answers.
Here is the complete script, and yes its a shell script but it calls php scripts. Sorry for my mistake.

#!/bin/sh


LOGDIR=/srv/DOWNLOAD_FILE=/tmp/si_downloads_$(date +"%Y%m%d_%H%M%S_%N")
MAX_DOWNLOADS=1
HOURS_AGO=24
SITENAME_PATTERN="^(http:\/\/)?.*DOMAIN\-?HERE\.[com]"
TITLE="XXXX"
PHP_FILE=/usr/local/bin/downloadcheck.php
MAILTO="XXXXXX"

days_ago=`expr 1 + $HOURS_AGO / 24`

echo -n '' > $DOWNLOAD_FILE.unsorted

awk '/"GET \/avs\/.*\.rm.* HTTP\/[1-9]\.[0-9]" 200/ {print $3,$7,$4,$11}' $LOGDIR/access_log >> $DOWNLOAD_FILE.unsorted
awk '/"GET \/avs\/.*\.rm.* HTTP\/[1-9]\.[0-9]" 200/ {print $3,$7,$4,$11}' $LOGDIR/access_log.processed >> $DOWNLOAD_FILE.unsorted

for logfile in `find $LOGDIR/access_log*.gz -mtime -$days_ago`;
do
gunzip -c $logfile | awk '/"GET \/avs\/.*\.rm.* HTTP\/[1-9]\.[0-9]" 200/ {print $3,$7,$4,$11}' >> $DOWNLOAD_FILE.unsorted
done

sort $DOWNLOAD_FILE.unsorted > $DOWNLOAD_FILE

php $PHP_FILE $DOWNLOAD_FILE $MAX_DOWNLOADS $MAILTO $HOURS_AGO $SITENAME_PATTERN $TITLE

rm $DOWNLOAD_FILE.unsorted
#rm $DOWNLOAD_FILE
 
I can't see anything wrong with it either. Have you tried running this manually by pasting it into a shell prompt?

Code:
awk '/"GET \/avs\/.*\.rm.* HTTP\/[1-9]\.[0-9]" 200/ {print $3,$7,$4,$11}' /srv/www/vhosts/XXXXXXXX/statistics/logs

(By the way, please post your code between [ignore]
Code:
...
[/ignore] tags to make it more readable.)

Annihilannic.
 
Mh guess you mean

Code:
awk '/"GET \/avs\/.*\.rm.* HTTP\/[1-9]\.[0-9]" 200/ {print $3,$7,$4,$11}' /srv/[URL unfurl="true"]www/vhosts/XXXXXXXX/statistics/logs/access_log[/URL]

this executed on terminal returns kind of

Code:
- /path/to/file/filename.rm [15/Jun/2009:01:00:19 "[URL unfurl="true"]http://www.domain.tld/updates.htm"[/URL]


Does this help in any way? Not for me so far.... *confused*
 
Yes, that's exactly what I meant, apologies for the omission.

Well, that seems to be working fine. So it must be a problem with the way the script is being run; how are you running it?

Annihilannic.
 
I was running it from console, run with
Code:
sh ./downloadcheck.sh
(this is name of the file posted above). I checked also that the LOGDIR exists, the .unsorted files in the tmp dir are also written but empty.
 
What operating system is this exactly? Have you tried running it with ksh instead perhaps? sh is usually the Bourne shell (although on some systems, e.g. HP-UX, it is the more advanced POSIX shell). The Bourne shell doesn't support some of the syntax in the script, e.g. the $(date ...) command substitution.

Annihilannic.
 
Hello and thanks for your help!

The system is an OpenSuse 10.3. I installed the ksh additionally and tried to call
Code:
ksh ./downloadchek.sh

same error as above with message
Code:
./downloadcheck: line 20: syntay error at line 27: `newline' unexpected

I am going nuts with this :(
 
Are there any funny characters in the script file? Try cat -vet downloadcheck.sh to check.

When I run it I just get the expected errors about missing files; the syntax seems to be okay:

Code:
$ sh downloadcheck.sh
awk: cmd. line:2: fatal: cannot open file `/srv/[URL unfurl="true"]www/vhosts/XXXXXXXX/statistics/logs/access_log'[/URL] for reading (No such file or directory)
awk: cmd. line:2: fatal: cannot open file `/srv/[URL unfurl="true"]www/vhosts/XXXXXXXX/statistics/logs/access_log.processed'[/URL] for reading (No such file or directory)
find: /srv/[URL unfurl="true"]www/vhosts/XXXXXXXX/statistics/logs/access_log*.gz:[/URL] No such file or directory
Could not open input file: /usr/local/bin/downloadcheck.php.
$ ls /tmp/si*
/tmp/si_downloads_20090618_092448_779991000
$

Annihilannic.
 
You saved my day! there were indeed some line breaks in the script. Dunno why but seems working now

(get "no such file access_log*.gz" and a php error but this seems to be an other topic)

Thanks so much for your help Annihilannic!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top