LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-13-2003, 06:36 PM   #1
pablogosse
LQ Newbie
 
Registered: Oct 2003
Posts: 2

Rep: Reputation: 0
Problem executing mv command inside shell script


Hi all. In a php application I'm writing under Redhat 9 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

Last edited by pablogosse; 10-13-2003 at 06:51 PM.
 
Old 10-13-2003, 09:30 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 11
Posts: 8,207

Rep: Reputation: 507Reputation: 507Reputation: 507Reputation: 507Reputation: 507Reputation: 507
Try:

mv ${SITE}$1 ${SITE}$2

___________________________________
Be prepared. Create a LifeBoat CD.
http://users.rcn.com/srstites/LifeBo...home.page.html

Steve Stites
 
Old 10-13-2003, 10:20 PM   #3
Walt_R
LQ Newbie
 
Registered: Oct 2003
Posts: 8

Rep: Reputation: 0
If I remember correctly, you need to cat variables together in a shell script.

IE:
mv `cat $site $1` `cat $site $2`

{` = accent graves}

Walt R.
 
Old 10-14-2003, 10:03 AM   #4
pablogosse
LQ Newbie
 
Registered: Oct 2003
Posts: 2

Original Poster
Rep: Reputation: 0
Hi guys. Thanks for the replys. 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.
 
Old 12-16-2009, 11:40 AM   #5
nbtest
LQ Newbie
 
Registered: Dec 2009
Posts: 1

Rep: Reputation: 0
Problem executing mv command inside shell script

i was able to run the mv command by using the format below for the shell script

`mv $1 $1`

Note command is enclosed in [` = accent graves]



Hope this helps!
 
Old 12-16-2009, 12:01 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by pablogosse View Post
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.
Glad you solved it

Without in any way wishing to be disrespectful to the members who responded in this thread (we're all volunteers, it's great that the community helps itself and all of us make mistakes some time -- or contribute nothing) none of the advice given is relevant. Thanks to the posters for contributing and I hope that the following critique spreads bash knowledge:
  • Regards mv ${SITE}$1 ${SITE}$2: in bash, variable name strings are terminated by any character that is not valid in a name. It is never wrong to enclose the name in { } but it is not necessary in this case.
  • Regards mv `cat $site $1` `cat $site $2`: this is wrong; it would give the mv command arguments of whatever the contents of any files identified by the $site, $1 and $2 variables happened to be -- possibly removing files.
  • Regards `mv $1 $1`: this would work to move file $1 to file $2 but the backticks are unnecessary (and it is safer to enclose the $1 and $2 in double quotes in case their values contain whitespace)
 
Old 12-16-2009, 12:05 PM   #7
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555
Catkin, you've got a typo in your third list point
 
Old 12-16-2009, 12:21 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by GrapefruiTgirl View Post
Catkin, you've got a typo in your third list point
Thanks for pointing it out Sasha -- that will teach me to copy-and-paste from posts, believing they actually said what I thought they said (and maybe even what they meant)! "Say what you mean and mean what you say". Anybody seen the movie that quote is from (one of my faves)? Went to check the name of the movie (Senior Members have senior moments) and found the line came from "Alice in Wonderland" in which the Cheshire Cat says it. Cool
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
executing konsole from shell script Meriadoc Linux - Newbie 10 07-10-2009 08:08 AM
Executing a shell script command!! vishamr2000 Programming 4 08-15-2005 12:33 AM
executing shell script on apache nooodles Linux - General 1 06-29-2004 01:51 AM
changing the user inside a shell script sanjith11 Programming 2 04-22-2004 07:44 AM
executing a shell script from C llama_meme Programming 2 04-01-2002 09:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:00 AM.

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
Open Source Consulting | Domain Registration