Passing information to a file on webpage

ok so I have a file on a website. this file is a plain text file

i need to be able to update the contents of this file from any internet enabled unix box.

does anyone have ideas on how it can be done, without using scp/ftp?

i know wget can be used to download the file:

wget http://www.website.com/file.txt

But what else can i do to actually update the file?

let's say i want to update the file with the word "Success:193434", the ideal solution would be as simple as this:

wget "Success:193434" http://www.website.com/file.txt

OS: Linux/SunOS/AIX

If it's on a website, why not update it directly?

$ cat updatefile.php
<?php
  $file = fopen( "file", "a" );
  fwrite( $file, "Success:193434\n" );
  fclose( $file );
?>
1 Like

thank you.

how can i run this on any internet enabled host? so that it updates a file on the webpage? i would like for this to be done from the command line. possibly by passing the parameters to the script.

The idea was that you add the file updatefile.php somewhere in your Webserver's document structure and call it using wget or curl.

For example:

$ curl http://webserver/updatefile.php
$ curl http://webserver/file
Success:193434
$ curl http://webserver/updatefile.php
$ curl http://webserver/file
Success:193434
Success:193434

You can modify the PHP to take parameters and update the file with those if you wished (so it doesn't have to be static updates).

i.e.

$ cat updatefile.php 
<?php
  $file = fopen( "file", "a" );
  fwrite( $file, $_GET['p1'] . " - " . $_GET['p2'] . "\n" );
  fclose( $file );
?>
$ curl http://webserver/updatefile.php"?p1=Hello&p2=World"
$ curl http://webserver/file                              
Success:193434
Success:193434
Hello - World
1 Like