Jump to content

Database To Shell Script with PHP


mark007

Recommended Posts

Hi all,

 

Rewording a problem I had before.

 

I am trying to take a string from a database and read it through php, and write it directly to a unix file. Its all very easy but I can do everything but stop php messing with my database string. It is constantly reading parts literally, and other parts as being parts that need to be escaped. I don't want any of this. I want it untouched and written to file.

 

So here is my code that has my database value and is about to write it to file.

 

My db_value as seen in phpMyAdmin is the following (its a worst case scenario but I expect my shell script to get this string exactly and untouched).

 

 

\\\\"\\\\&\\\\'<\\\\>\\\\'\\\'\\'\'

$argument=escapeshellarg($db_value);
$Shell_Command="/tmp/write_file.sh " . $argument;

 

My shell script I know to be correct, because if i manually give it this string, hand escaped, it prints it correctly to file exactly.

 

Is this possible? PHP seems to do some removal of the \\\\ and it sees it as \\. The shell script only sees 2 starting \\'s.

Using addslashes($db_value) makes things even worse, because characters like " get a backslash put in front of them then, and my shell script sees too many backslashes (5 starting slashes instead of 4 written to file like \\\\\" instead of \\\\").

 

There is no combination that will let my shell script receive four simple starting slashes. I either get 2, or 5.

Link to comment
https://forums.phpfreaks.com/topic/135317-database-to-shell-script-with-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.