Want to edit a sh file using php code


 
Thread Tools Search this Thread
Top Forums Web Development Want to edit a sh file using php code
# 1  
Old 12-24-2012
Want to edit a sh file using php code

Hi friends,

I want to edit sh file using php, i have tried different method. but its shows permission issues.

Folder path : xyz permission :0755 owner: 545 group: 0
filename : abc.sh permission :0644 owner:0 group: 0

how to edit these files using php/
i have use below codes, but not got any success
Code:
$file =$_SERVER['DOCUMENT_ROOT']."xyz/abc.sh";
chmod($file,0777);
exec('chown 545 $file');
exec('chmod 755 $file');

# 2  
Old 12-24-2012
This is not a bug in your program. You genuinely, actually do not have permission to chown and chmod from a webserver because of what your file permissions are. If your webserver doesn't own the files, it can't chmod. And even if it does, you can't chown. Root has to do that.
# 3  
Old 12-24-2012
Quote:
Originally Posted by Corona688
This is not a bug in your program. You genuinely, actually do not have permission to chown and chmod from a webserver because of what your file permissions are. If your webserver doesn't own the files, it can't chmod. And even if it does, you can't chown. Root has to do that.
Can we give permission from root to this file, so we can edit this file using php. we have root access.
# 4  
Old 12-28-2012
It is really not a good idea to run your CGI scripts as root. If someone comprosmises your web server they have won instant access to everything. If someone finds a bug in your program they can exploit it for root access. If your program misbehaves, it can damage anything. There's a reason most things don't run as root, and a reason webservers in particular get very little access to anything -- anyone in the world can cause a request to happen, and can inject any data they want with ease.

You could perhaps use sudo to allow your webserver to run very specific things as root, so you could do system("sudo /path/to/script.sh"); Don't give it a blank cheque. Only let it run very specific scripts, and write those scripts very carefully.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

C++ Edit code

Hi guys, I am learning C++ on my own and i wanna redit the code using classes and heritance to revamp the code below. example class for the card attributes -suit , - rank, - face and also class deck to contain shuffle and a class player with the function to setcard and a function handonecard... (1 Reply)
Discussion started by: ment0smintz
1 Replies

2. Programming

Are there any C code r instruction to see where is the creation or last edit for the file

Are there any C or termina instructin code or instruction to see where is the creation or last edit for the file (1 Reply)
Discussion started by: fwrlfo
1 Replies

3. Web Development

edit a file with PHP.

Ok here is what I have going on. I am listing the contest of a directory so I can edit and delete files. The code I am using to do that is below (Other then editing as it does not work). <?php $directory = ("enctlfiles/"); $dir = opendir($directory); $files = array(); while (($file =... (10 Replies)
Discussion started by: GroveTuckey
10 Replies

4. Shell Programming and Scripting

Best way to edit a file

looking for a script or command to push out from a centralized machine to multiple machines. I have the software in place that will do this already, but I need to tell it what command to run on each machine with this file. what I need is a script or command to edit a file in a specific manner.... (13 Replies)
Discussion started by: skunky
13 Replies

5. Shell Programming and Scripting

Script to Check & Edit Content of a file (Addition of comma in each lines of code)

Hi all, I need to write an automated bash shell script which performs such operations: 1. Grep the header of everyline with the initial of "T" in "FILE_A" 2. Perform a for loop, Count the numbers of comma in the line of code, if (no. of comma < 17) ADD the comma until 17; ... (2 Replies)
Discussion started by: big_nutz
2 Replies

6. Shell Programming and Scripting

edit file

I have a file containing dates like below 2010 1 02 2010 2 01 2010 3 05 i want the dates to be like below 20100102 20100201 20100305 i tired using awk '{printf "%s%02s%02s",$1,$2,$3}' But it does not work,it puts all the dates in one line,i want them in seperate lines like the... (6 Replies)
Discussion started by: tomjones
6 Replies

7. Shell Programming and Scripting

Edit a file

I have file like cp -p /var/adm/ /tmp1/tmp1.log cp -p /var/adm/ /tmp1/tmp2.log cp -p /var/adm/ /tmp1/tmp3.log cp -p /var/adm/ /tmp1/tmp4.log I need to re-write the file like: cp -p /var/adm/tmp1.log /tmp1/ cp -p /var/adm/tmp2.log /tmp1/ cp -p /var/adm/tmp3.log /tmp1/ cp -p... (3 Replies)
Discussion started by: h_banka
3 Replies

8. Shell Programming and Scripting

Script to Edit the file content and create new file

I have a requirement, which is as follows *. Folder contains list of xmls. Script has to create new xml files by copying the existing one and renaming it by appending "_pre.xml" at the end. *. Each file has multiple <Name>fileName</Name> entry. The script has to find the first occurance of... (1 Reply)
Discussion started by: sudesh.ach
1 Replies

9. Infrastructure Monitoring

snmp,how to edit code generated by mib2c?

Hi, I'm reading net-snmp site, using C language and unix environment, I have manager ( do get/set command), agent and server ... I'm trying to monitor cpu, memory and disk usage and get Ip address of server and send the value back to agent, stored in variable which enable manager to gets the... (1 Reply)
Discussion started by: zainab
1 Replies
Login or Register to Ask a Question