Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem executing mv command inside shell script

Status
Not open for further replies.

pgosse

Programmer
Sep 26, 2001
42
CA
Hi all. In a php application I'm writing I'm using php's system() function to execute a shell script.

This shell script takes two variables, an old directory location and a new directory location, and should move the old directory to the new directory.

Here's the script:

Code:
#!/bin/bash

# Params:
# $1 original directory name
# $2 new directory name

# set site webroot
SITE=/path/to/web/root

if [ ! -d $SITE ] ; then
        exit 10
elif [ ! -d $SITE$1 -o -d $SITE$2 ] ; then
        exit 20
else
#       exit 30
        mv $SITE$1 $SITE$2
fi

So the executing command would be

Code:
mv /path/to/web/root/and/olddirectory/ /path/to/web/root/and/newdirectory/

When this script executes it returns an exit code of 1 (even if I wrap $SITE$1 $SITE$2 in quotes), but if I comment out the mv command and uncomment the exit 30 line, it returns an exit value of 30.

I've been looking in my reference manuals but I can't seem to find what the exit code 1 for the mv command is.

The only thing I can see is that it might be is a syntax error in the mv command, but if that's it I'm lost as to what it is. I've executed the mv command from the command line, using the value of $SITE and $1 and $2 and it works fine.

If anyone can shed some light on what this could be I would greatly appreciate it. I realize that it's probably something quite small but I'm relatively new to shell scripting under Linux so any help would be great.

Thanks in advance,
Pablo
 
Actually the problem was with the permissions on the shell script and on the site itself.

Here's the breakdown:

/cmsutil/CMS_move_area_dirs (gossep:gossep)
/path/to/site/dir/to/move/ (gossep:gossep)

However the shell script when being executed is running under the privelidges of the apache user, so for that reason it was failing. I need to talk to my sysadmin about setting it up such that whenever the shell scripts execute they do so under the permissions of the gossep user, even when called by apache.

The workaround for now was to chown everything under the site to apache:apache and since this isn't a production site I'm okay with that, just wanted to get everything working properly.

Thanks,
Pablo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top