Ubuntu – How to create a new text file with a new name from a phpscript everytime it is executed

PHPpipescripts

I use a Php script which is actually for sending sms from the terminal using an online sms service 160by2

What it does is opens the terminal,asks for the number then the sms and it is sent…

Now i want the text in that sms to be copied to a new file everytime.

for example like text1.txt then text2.txt and it goes on incrementing every time.

If its not possible from php script then may be i can rite a shell script that first executes the php script and then makes the new file with some command and copies the text in the sms into that file.

I want to know that command( i guess pipelining is also used) and also,how to make the file name different everytime?

I don't know shell scripting.

but in a normal programing language,like c/c++/java,the way would be a loop in which a variable is incremented everytime and then passed as a parameter to the name..is anything like this possible in shell scripting?

Best Answer

here's a php script that writes a file named using the unix timestamp:

#!/usr/bin/env php
<?php
file_put_contents("file" . ((int) microtime(true)) . ".txt", file_get_contents("/proc/cpuinfo"));
?>

if you want fill the file from i.e. stdin, change /proc/cpuinfo to php://stdin

here's a shell script that does the same as the original php script

#!/bin/sh
cat /proc/cpuinfo | tee "file`date +%s`.txt" > /dev/null

you can chmod +x both of these and execute them

Related Question