Page 1 of 1

Compress Query to Tar

Posted: Wed Apr 04, 2007 10:00 am
by luyznascimento
Hi,


I am new to this FORUM and I hope to count with your precious support. I am trying to, after querying data from a DB, create on the fly "a tar file on my server". Is it possible?

My site is located on a Linux server.

I looked around the web for a solution but the possibilities found became frustrating.

Thank you for your attention.

LuyzNascimento

Posted: Wed Apr 04, 2007 10:02 am
by feyd
Unless my memory is failing, you would simply write the data to a file then call tar via system(), exec() or shell_exec().

Posted: Thu Apr 05, 2007 7:09 am
by luyznascimento
feyd wrote:Unless my memory is failing, you would simply write the data to a file then call tar via system(), exec() or shell_exec().

Hummmmmmmmmmmmm...nice try. I will do it now and see what happens! I will try not to explode anything with this :-))))


Kind Regards,
Luyz Nascimento.

Posted: Mon Apr 16, 2007 10:03 am
by luyznascimento
luyznascimento wrote:
feyd wrote:Unless my memory is failing, you would simply write the data to a file then call tar via system(), exec() or shell_exec().

Hummmmmmmmmmmmm...nice try. I will do it now and see what happens! I will try not to explode anything with this :-))))


Kind Regards,
Luyz Nascimento.

No it does not work. I tried so many different things since then but I just round and round...now where to go?

Far from now I tried to learn shell programming. I became with the following:

Code: Select all

#!/bin/sh
#

if test -z $1

then

        echo "empty directory - please inform one..."

else

        cd "$1/"

        tar -cf "$1.tar" cbq*

        #ls -al
fi
I call the above statement with:

Code: Select all

shell_exec ('. cd.sh DirName');
But nothing happens the way I expected it to throught SHELL_EXEC WITHIN PHP. But, instead, if I call that file over telnet prompt - works perfectly. It changes to the dir informed like: [root@controle tar]# . cd.sh DirName -, and do the rest of command...

Any suggestions?

Luyz Nascimento

THE ANSWER OR WAY OUT AS U PREFER...

Posted: Tue Apr 17, 2007 8:03 am
by luyznascimento
luyznascimento wrote:
luyznascimento wrote:
feyd wrote:Unless my memory is failing, you would simply write the data to a file then call tar via system(), exec() or shell_exec().

Guys and Girls,


After a long time searching, seeking, willing this information, this morning here in my bedroom, I woke up with something strange living in my ideas...so I got this happening:

1 - I seeked if PHP would have a function to CHANGE DIRECTORY - YES IT HAS: CHDIR("DIRECTORY_NAME"). With this I changed the way things acts - I was trying to execute the "CD" command line from linux into SHELL_EXEC - won t work as expected to. = WRONG WAY !!!

2 - With the new code on my hands I needed to develop a simple condition to discover if UNDERSTANDS the change directory situation and WORKED!!!

3 - the rest was only success and I DIVIDE IT WITH YOU BELOW, BECAUSE IT WAS NOT A WASTED OF TIME ANYWAY - AS WE CAN SEE - I LEARNED AND TRY TO SAVE YOUR TIME EITHER, TEACHING YOU? Well its up to you, I guess.

Code: Select all

The "$dir" variable - comes dynamically on my code, ok?

if (chdir("$dir/")){

shell_exec ('tar -cf '.$dir.'.tar cbq*');

}

Kind Regards,
Luyz Nascimento