Web Hosting Talk







View Full Version : sh script to write to a file


tuvok
11-26-2001, 11:19 AM
Hey guys, any ideas on the coding for an sh script that will take info from a form on a webpage and write it to a file on the server i.e if users fill in a form, i want the info to be write to say a file named say form.txt or just form

thank for the input or for pointing me in the right direction..

ffeingol
11-26-2001, 11:33 AM
Why would you want to do this as a shell script and not Perl or PHP?

Frank

bobcares
11-26-2001, 01:59 PM
Hi! Frank is correct.. Perl and php are very good options for this work.
I have added below the code for both the form and the php file that'll process it . I hope this works for you.
1) The html file has one text box email -

<form action="formsubmit.php">
<input type="text" name="email" value="youname@yourdomain.com">
<input type="submit">
</form>

2) The php code looks like

<?
$fd = fopen ("formdata.txt", "a");
fputs ($fd, "$email\n");
fclose ($fd);
?>

Have a great day :)

Regards
Amar

tuvok
11-26-2001, 03:07 PM
thanx for he input guys, but how do i specify where the file is writen to i.e if i manted the file dropped in /etc/rc.d/folder

and how would i overcome permission problems, even if i am the owner of the box.....will linux allow me to write a file in a folder that only root has rights to....

also what if i want it to delete or over write the same file the next time i write a new one to the directory


thanx

bobcares
11-26-2001, 03:10 PM
Hi!
Mostly linux server have apace running as nobody. So the file has to have the permission for nobody:nobody to access.
Alternatively you must compile apache with suexec. This would enable you to save the files under your ownership.
Have a great day :)

Regards
amar

Badone
11-26-2001, 07:50 PM
FYI, if you were to use a shell script it could look something like this.

#!/bin/sh
echo "What you want" >> whereyouwant.txt

bobcares
11-27-2001, 02:29 AM
Hi Matt,
You are correct on the code. However, I wonder how one can transfer the contents of a web form to a text file using a shell script. I'd really appriciate some help on that.

Have a great day :)

Regards
Amar

netsolutions
11-27-2001, 02:36 AM
bobcares, if you keep this up your going to run yourself out of business ;)

bobcares
11-27-2001, 02:39 AM
Originally posted by netsolutions
bobcares, if you keep this up your going to run yourself out of business ;)


I'm sorry if I offended anyone.
I was actually curious to know how to write a shell script.
I did not mean to hurt anybody's feelings.
I'm sorry if I did.

Have a great day :)

Regards
amar

netsolutions
11-27-2001, 02:51 AM
No, no, no. Relax Bob. I meant it as a joke and a compliment to you. Your business offers hosting companies tech support and you help a lot of people on WHT. You didn't affend anyone. I was just joking.

bobcares
11-27-2001, 03:00 AM
Hi!
Thanx. :)
I really appriciate it...

Have a great day :)

Regards
Amar