Board Logo
Go To Bottom

Printable Version  
[ Total Views: 475 | Total Replies: 13 | Thread Id: 20783 ]
Author: Subject: Who knows shell script?
Memberamazer
Bishop of Volkswagenism
kombi pilot
******


Avatar


Posts: 3187
Threads: 308
Registered: August 26th, 2002
Member Is Offline

Location: Wollongong
Theme: UltimaBB Pro Blue ( Default )
Mood: Peachy!

posted on March 28th, 2004 at 11:55 AM
Who knows shell script?


I want to create a simple little hit counter in shell. I figure I will store a value in a file. Read it when the page is accessed using SSI and write a new value over the top. Trouble is, I am useless at scripting. So far what I have is this:

#!/bin/sh
NUM=`cat counter.dat`
let "NUM=$NUM+1"
echo $NUM >> counter.dat

but that seems to be concatenating the file.
How do I overwrite?



Thanks in advance.
Chris.


NEVER MIND. seems to be working now. spooky.


[Edited on 28-3-2004 by amazer]




Chris.... kombi pilot, oval dreamer... finisher #26971 2005 city to surf
http://members.ozemail.com.au/~amazer39/vwsigline.jpg
Super Administratorvanderaj
A.k.a.: Andrew van der Stock
Super Administrator
a suffusion of yellow
*********

Rank Avatar

Avatar


Posts: 3123
Threads: 438
Registered: August 26th, 2002
Member Is Offline

Location: Colorado Springs, CO, USA
Theme: UltimaBB Pro Yellow
Mood: In the family again

posted on March 28th, 2004 at 12:22 PM


> is overwrite
Memberamazer
Bishop of Volkswagenism
kombi pilot
******


Avatar


Posts: 3187
Threads: 308
Registered: August 26th, 2002
Member Is Offline

Location: Wollongong
Theme: UltimaBB Pro Blue ( Default )
Mood: Peachy!

posted on March 28th, 2004 at 01:54 PM


freaky how I must have accidently deleted one of the > and stumbled upon the solution. bizarre. So now that is working fine when I execute the script manually from a terminal window. But it isnt working when I call it through my web???? Its not giving any errors, it just doesnt seem to be writing to the file. Its not to do with refresh as I have checked the datafile.

#!/bin/sh
NUM=`cat ../htdocs/mystuff/counter.dat`
let "NUM=$NUM+1"
echo $NUM > ../htdocs/mystuff/counter.dat

<body>
<b>Welcome to my world!</b><br>
You are visitor number: <br>
<!--#exec cgi="/cgi-bin/counter.cgi" -->
<!--#include file="counter.dat" -->
<!--#config timefmt="%d/%m/%y" -->Today's Date:
<!--#echo var="DATE_LOCAL"--><br>
</body>

IM guessing its something to do with pathnames

dont know how to represent this dir structure here. cgi-bin and htdocs are on the same level.

>cgi-bin dir > counter.cgi
>htdocs dir > my stuff dir > welcome.shtml, counter.dat




Chris.... kombi pilot, oval dreamer... finisher #26971 2005 city to surf
http://members.ozemail.com.au/~amazer39/vwsigline.jpg
MemberMentat
Casual Dubber
*


Avatar


Posts: 28
Threads: 9
Registered: March 7th, 2004
Member Is Offline

Theme: UltimaBB Pro Blue ( Default )
Mood: Sober

posted on March 28th, 2004 at 02:30 PM


What are the permissions on the counter.cgi.

Is the webserver user (normally apache or nobody) able to modify the .dat file and execute the counter.cgi?

Regards
- Adam
Memberamazer
Bishop of Volkswagenism
kombi pilot
******


Avatar


Posts: 3187
Threads: 308
Registered: August 26th, 2002
Member Is Offline

Location: Wollongong
Theme: UltimaBB Pro Blue ( Default )
Mood: Peachy!

posted on March 28th, 2004 at 05:13 PM


well that would have been part of the problem, thanks.
Changed the permissions to 755 for the cgi and 777 for the dat file but still no worky. this sucks.




Chris.... kombi pilot, oval dreamer... finisher #26971 2005 city to surf
http://members.ozemail.com.au/~amazer39/vwsigline.jpg
Memberamazer
Bishop of Volkswagenism
kombi pilot
******


Avatar


Posts: 3187
Threads: 308
Registered: August 26th, 2002
Member Is Offline

Location: Wollongong
Theme: UltimaBB Pro Blue ( Default )
Mood: Peachy!

posted on March 28th, 2004 at 05:40 PM


i AM getting an error message.

Premature end of script headers: /spare0/csci399/clf02/cgi-bin/counter.cgi




Chris.... kombi pilot, oval dreamer... finisher #26971 2005 city to surf
http://members.ozemail.com.au/~amazer39/vwsigline.jpg
Membermodulus
A.k.a.: Peter Hill
Veteran Volks Folk
*****


Avatar


Posts: 2009
Threads: 76
Registered: July 1st, 2003
Member Is Offline

Location: Melbourne
Theme: UltimaBB Pro White
Mood: modular

posted on March 28th, 2004 at 06:44 PM


I don't know Jack about *Shell* CGI, but in CGI programs I write in Perl, C etc., you need to give a valid response to the call,typically sending back an OK error code and some text output (tho' other options abound). Certainly yr. CGI program needs to respond, not just execute and exit.

hth




Peter Hill
1975 Type 2 Double Cab
modulus.com.au
MemberMentat
Casual Dubber
*


Avatar


Posts: 28
Threads: 9
Registered: March 7th, 2004
Member Is Offline

Theme: UltimaBB Pro Blue ( Default )
Mood: Sober

posted on March 28th, 2004 at 06:53 PM


Are you editing the files live on the server using vi or are you editing them in notepad/other windows programs...

windows uses CRLF as a new line charachter which can cause problems on unix type boxen.
Memberamazer
Bishop of Volkswagenism
kombi pilot
******


Avatar


Posts: 3187
Threads: 308
Registered: August 26th, 2002
Member Is Offline

Location: Wollongong
Theme: UltimaBB Pro Blue ( Default )
Mood: Peachy!

posted on March 28th, 2004 at 07:17 PM


editing with pico on the server.

got rid of the header error. Forgot to put the echo "Content-type: text/plain\n\n" line in.

But now!!! and I am sure I wasnt getting this before, I'm getting this...

/spare0/csci399/clf02/cgi-bin/counter.sh: let: not found

file now reads:

#!/bin/sh
echo "Content-type: text/plain\n\n"

NUM=`cat ../htdocs/mystuff/counter.dat`
let "NUM=$NUM+1"
echo $NUM > ../htdocs/mystuff/counter.dat




Chris.... kombi pilot, oval dreamer... finisher #26971 2005 city to surf
http://members.ozemail.com.au/~amazer39/vwsigline.jpg
Membermodulus
A.k.a.: Peter Hill
Veteran Volks Folk
*****


Avatar


Posts: 2009
Threads: 76
Registered: July 1st, 2003
Member Is Offline

Location: Melbourne
Theme: UltimaBB Pro White
Mood: modular

posted on March 28th, 2004 at 07:27 PM


That looks awful; "let" used to be found in the most crippled BASICS.

Also I would think that "NUM" either needs a $ sign or doesn't....

surely those 'n's need to be escaped...


#!/bin/sh
echo "Content-type: text/plain\n\n"

$NUM=`cat ../htdocs/mystuff/counter.dat`
$NUM++
echo $NUM > ../htdocs/mystuff/counter.dat

but, I'm like a blind man in a dark room looking for a black cat that may not be there; I don't know Shell script syntax...

hth




Peter Hill
1975 Type 2 Double Cab
modulus.com.au
Memberamazer
Bishop of Volkswagenism
kombi pilot
******


Avatar


Posts: 3187
Threads: 308
Registered: August 26th, 2002
Member Is Offline

Location: Wollongong
Theme: UltimaBB Pro Blue ( Default )
Mood: Peachy!

posted on March 28th, 2004 at 07:37 PM


I know it sucks.

$NUM++ is a no go.
it takes value of $NUM first
so it ends up 280++ and doesnt know what to do with it. Tried putting brackets everywhere to no avail. Not sure that it understands ++ at all.

Ive resorted to beer.




Chris.... kombi pilot, oval dreamer... finisher #26971 2005 city to surf
http://members.ozemail.com.au/~amazer39/vwsigline.jpg
Memberamazer
Bishop of Volkswagenism
kombi pilot
******


Avatar


Posts: 3187
Threads: 308
Registered: August 26th, 2002
Member Is Offline

Location: Wollongong
Theme: UltimaBB Pro Blue ( Default )
Mood: Peachy!

posted on March 28th, 2004 at 07:50 PM


:beer
Never underestimate the power of beer and a Hunters and Collectors session on the CD player.

#!/bin/sh
echo "Content-type: text/plain\n\n"

NUM=`cat ../htdocs/mystuff/counter.dat`
NUM=`expr $NUM + 1`
echo $NUM > ../htdocs/mystuff/counter.dat

ITS ALL GOOD!
The horns, the percussion..

"Do you see what I see
Do you se what I seeee...."




Chris.... kombi pilot, oval dreamer... finisher #26971 2005 city to surf
http://members.ozemail.com.au/~amazer39/vwsigline.jpg
Membermodulus
A.k.a.: Peter Hill
Veteran Volks Folk
*****


Avatar


Posts: 2009
Threads: 76
Registered: July 1st, 2003
Member Is Offline

Location: Melbourne
Theme: UltimaBB Pro White
Mood: modular

posted on March 28th, 2004 at 07:56 PM


Almost all good.

I'm guessing the point of having you write a 'counter' program is to highlight the need for file locking and atomic operations, and those aren't there yet; imagine you've got 5 users simultaneously wanting to read the value of the counter and increment it....last one to write wins....

hth




Peter Hill
1975 Type 2 Double Cab
modulus.com.au
Memberamazer
Bishop of Volkswagenism
kombi pilot
******


Avatar


Posts: 3187
Threads: 308
Registered: August 26th, 2002
Member Is Offline

Location: Wollongong
Theme: UltimaBB Pro Blue ( Default )
Mood: Peachy!

posted on March 28th, 2004 at 08:02 PM


naaaaah, thats a different subject LOL.
Distributed systems, operating systems and databases was about locks. Now I just need to know different server shit.
PHP ASP CGI SSI PL SH all those acronyms :P
I'll move on to some harder liquor when I have to do any serious regex stuff. I have nightmares about that crap. This is my second attempt at this subject. Walked out of the exam with the shits 15 minutes into it last year.




Chris.... kombi pilot, oval dreamer... finisher #26971 2005 city to surf
http://members.ozemail.com.au/~amazer39/vwsigline.jpg
MemberBrad
Wolfsburg Elder
*******


No Avatar


Posts: 3764
Threads: 332
Registered: August 24th, 2002
Member Is Offline

Location: SE QLD, Mt Nebo
Theme: UltimaBB Pro Blue ( Default )
Mood: Manx Buggy Building

posted on March 28th, 2004 at 11:23 PM
mmm


few ??? for you ??

Do you have a text book ?
Can yu read it ?? :P:P

What shell r u using ? I am guessing Bourne by your sh directory.
You seem to have some weird ass metscharacters in there which is why I ask.
Shouldn't you have some mor $$ signs in order to echo $ Num > to file ??

Now I dunno exactly what you are trying to do but you don't appear to be writting to the file correctly. I would try adding $echo $Num

Echo is a shell command that displays all its arguemenst to standard output and $ exapands the value of the vaiable which is what you want .

ALso why do you have NUM=`expr $NUM + 1` to incriment count ? What is the expr in aid of ? I would think in bourne the ((Num = Num + 1 )) would be fine to incrimnet loop / local variable of Num each time. If this isn't fancy enough try

set Num =1
@ Num ++
echo $Num > file name etc etc .......

Am I making any sense ?




Brad
Why copy when you can own an original ?
Meyers Manx Australia
Memberamazer
Bishop of Volkswagenism
kombi pilot
******


Avatar


Posts: 3187
Threads: 308
Registered: August 26th, 2002
Member Is Offline

Location: Wollongong
Theme: UltimaBB Pro Blue ( Default )
Mood: Peachy!

posted on March 29th, 2004 at 10:21 AM


Brad, the last listing works.
I tried using more $ and less $ and all sorts of things for a whole day. This is the ONLY way I can get it to work.

I dont have a text book. Generally I dont read, the text books I do have , I dont read (much). They usually cost around $80-$100. Cant claim the books on tax if I dont have a job nor income so dont get them. Anything in a book can also be found on google and I dont need to know the alphabet to look up an index.

In contrast the perl script I wrote after that, took me about 1 hour. Bastards. All day to write 4 lines, 1 hour to write about 20.




Chris.... kombi pilot, oval dreamer... finisher #26971 2005 city to surf
http://members.ozemail.com.au/~amazer39/vwsigline.jpg


  Go To Top


Powered by GaiaBB, © 2011 The GaiaBB Group
(C) 2001-2025 Aussieveedubbers

[ Queries: 40 ] [ PHP: 1.4% - SQL: 98.6% ]