LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-14-2011, 06:45 AM   #1
tamer1009
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Rep: Reputation: Disabled
PHP and Bash Issue


Hello,

I've been working on a php file editor to edit files on linux.

So this is my php code which writes text to a file, but I got some errors.

PHP Code:
$content $_POST['exec'];
$toexec 'echo '$content .' > test.txt';
echo 
$ssh->exec($toexec); 
For example I'm editing php.ini. I got this error with the code:
Code:
[PHP] bash: line 1: : command not found bash: -c: line 2: syntax error near unexpected token `;;' bash: -c: line 2: `;;;;;;;;;;;;;;;;;;; '
";;;;;;;;;;;;;;;;;;;" is the beginning of that php.ini

I've tried everything with this line:
$toexec = 'echo '. $content .' > test.txt';

Thanks
 
Old 06-14-2011, 06:49 AM   #2
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
The file should have the correct shebang (the php shebang begins with #!) at the top.
probably #!/usr/local/bin/php.
"which php" can give you the correct path in your system.
 
Old 06-14-2011, 07:02 AM   #3
papa2ae
LQ Newbie
 
Registered: Jun 2011
Posts: 10

Rep: Reputation: Disabled
@ssrameez

Im trying to learn something similar.

Wonder what file should he actually add it to.

The actual php file or the bash file? :S

ty
 
Old 06-14-2011, 07:04 AM   #4
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
To the PHP file
 
Old 06-14-2011, 07:05 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,629
Blog Entries: 4

Rep: Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999
And what if your incoming file consisted of:

rm -rf /



PHP contains commands to write data to files. Use them. It is insane to blindly receive any file from anyone and then exec it.
 
Old 06-14-2011, 07:10 AM   #6
papa2ae
LQ Newbie
 
Registered: Jun 2011
Posts: 10

Rep: Reputation: Disabled
Quote:
And what if your incoming file consisted of:

rm -rf /



PHP contains commands to write data to files. Use them. It is insane to blindly receive any file from anyone and then exec it.
I guess, he should strip slashes then, as then and only then rm -rf / wouldnt work. However, i think like he said he is editing php.ini - which consists of many slashes, without them, it will render the php.ini file useless.

What you think?
 
Old 06-14-2011, 07:15 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 16,350

Rep: Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908
Welcome to LinuxQuestions.

In addition your PHP code needs to be surrounded by PHP tags.
<?php
?>

Are you writing a web application or wanting to use the PHP command line.
 
Old 06-14-2011, 07:19 AM   #8
tamer1009
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
I'm passing commands from a webform to a bash script.

But I need to write $content to /etc/php.ini

I think it's also possible in PHP only, but I couldn't find it.

EDIT: Writing to /etc/php.ini in PHP is not possible because you need to be root, so it's only possible through an SSH command. That's what I tried but got that error.

Last edited by tamer1009; 06-14-2011 at 07:26 AM.
 
Old 06-14-2011, 07:28 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 16,350

Rep: Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908
You can use either but since your first post is PHP then stick with it.
To read/write files using php
http://www.w3schools.com/php/php_file.asp
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
weird PHP compile issue- module shows in "php -m" but not in phpinfo call hbbtstar Linux - Software 1 08-28-2009 04:14 PM
php issue dody1313 Solaris / OpenSolaris 3 03-20-2008 02:20 PM
bash to php zybot5785 Programming 3 04-10-2007 03:44 PM
php issue petenyce Linux - Newbie 1 09-16-2005 09:38 AM
php issue in 8.1 bitfuzzy Slackware 1 11-05-2003 01:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration