Shell Script from PHP not able to cp or mv or anything


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script from PHP not able to cp or mv or anything
# 1  
Old 08-16-2012
Data Shell Script from PHP not able to cp or mv or anything

Hi there,

For some reason my maintenance mode shell script is not working. Both shell scripts are chmod +x'd, and owned by apache, running from php using exec(), maintenance.html and htaccessmaintenance are both owned by apache.

My code is:
Code:
#/bin/bash

cp maintenance.html /var/www/vhosts/$1/httpdocs/maintenance.html
if [ -f /var/www/vhosts/$1/httpdocs/maintenance.html ]
then

wall 'copied'

fi

chown apache:psacln /var/www/vhosts/$1/httpdocs/maintenance.html
if [ -f /var/www/vhosts/$1/httpdocs/.htaccess ]
then
chown apache:psacln /var/www/vhosts/$1/httpdocs/.htaccess
mv /var/www/vhosts/$1/httpdocs/.htaccess /var/www/vhosts/$1/httpdocs/.htaccess.bak
chown apache:psacln /var/www/vhosts/$1/httpdocs/.htaccess.bak
fi
cp htaccessmaintenance /var/www/vhosts/$1/httpdocs/.htaccess
chown apache:psacln /var/www/vhosts/$1/httpdocs/.htaccess

It works executed from the command line, but not from PHP, no idea why. I know a lot of the chown's are overkill, but I'm grasping at straws now.
# 2  
Old 08-16-2012
What is the PATH variable when seen inside PHP? That is probably the issue.
Add (example):
Code:
export PATH=/usr/bin:/usr/local/bin

as the first line of the script. Or. You can also source /etc/profile and .profile
This is probably a better solution.
# 3  
Old 08-16-2012
It also depends who those directories belong to. If they're not writable by the apache group, apache and things apache runs probably can't touch them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Help to integrate Shell script with PHP

I have a shell script which takes user name and server name from the user and check the authentication type on that server like LDAP or VAS or local. It also provides various other info also such as owner of the ID and etc. I need this script to work on the browser where user can directly input... (2 Replies)
Discussion started by: Bhuwan Nazkani
2 Replies

2. Shell Programming and Scripting

New line in shell/PHP script

hi all, I wrote a PHP script inside which am calling a shell script, In shell script, i used echo to output some results. In PHP script i just gave echo to the shell script output. But i couldn't enter the output in newline. Please help me! Thanks. PHP script <?php... (4 Replies)
Discussion started by: vidhyaS
4 Replies

3. Shell Programming and Scripting

how to convert a shell script to a php script for displaying next word after pattern match

I have a shell script which I made with the help of this forum #!/bin/sh RuleNum=$1 cat bw_rules | sed 's/^.*-x //' | awk -v var=$RuleNum '$1==var {for(i=1;i<=NF;i++) {if($i=="-bwout") print $(i+3),$(i+1)}}' Basically I have a pages after pages of bandwidth rules and the script gives... (0 Replies)
Discussion started by: sb245
0 Replies

4. Shell Programming and Scripting

PHP function in a shell script

Hi. I am writing a shell script for Ubuntu linux. Eventually I want my script to run every 10 mins via cron. This is what I am trying to do: php file: connect to mysql database get the last row input check date against previously saved date (on last run) if date>previous return... (4 Replies)
Discussion started by: daydreamer
4 Replies

5. Shell Programming and Scripting

Accessing php script from shell script

Hi I'm a newb to php scripts. My task requires me to run a shell script from within the php script which I believe I've figured out. What I'm trying to do now is output something to the web page from the called shell script. when I use "echo" from the called shell script I don't get any output... (3 Replies)
Discussion started by: airon23bball
3 Replies

6. UNIX for Dummies Questions & Answers

Shell Script to Auto Run PHP Script

Hello All! I am looking to build a monitoring script. The script should always run as a system service of some type and should always check that a PHP script is running. Maybe there is a way to assign a PHP script to a certain PID so that the monitor script that check for the PID in top... (4 Replies)
Discussion started by: elDeuce
4 Replies

7. Shell Programming and Scripting

Calling a shell script from php

Hi, I have a shell script and I'm trying to execute it from my php script. The command I'm using is: shell_exec("Script.sh"); Is this correct? It seems to not do anything for me. Not sure if this might be a permission issue or not. I have both scripts 777 permissions. Maybe I got the... (1 Reply)
Discussion started by: eltinator
1 Replies

8. Shell Programming and Scripting

Cannot run Shell script in PHP

Hello, I have written a code for uploading a file onto the server.The code is as follows: <? if ($_POST == "Upload File") { if( move_uploaded_file ($_FILES ,$target) ) { $tmpsrc = $_FILES ; echo... (2 Replies)
Discussion started by: michrods
2 Replies

9. Shell Programming and Scripting

Invoking Shell Script via php

list me commands to invoke a shell script from php once the submit button is clicked in the php page. Requirement is Once a submit button is clicked it should run a script that displays the outcome of the script in a html/php. Please help. Thanks in Advance, BubeshJ (2 Replies)
Discussion started by: bubeshj
2 Replies

10. Shell Programming and Scripting

Is it possible to execute shell script with PHP?

I'm trying to write a php script that can let user reset to the default password. I already have a shell script that does this job, so I wonder is it possible to execute shell script with PHP? If yes, then how? Thx in advance (1 Reply)
Discussion started by: Micz
1 Replies
Login or Register to Ask a Question