WebFaction
Community site: login faq

I'm creating a shell script to deploy from a test environment to staging. My script works but I'm experiencing strange behavior with the cp command.

#!/bin/bash
#
###################
#                 #
# Deploy to stage #
#                 #
###################
#
# remove the current stage environment
#
echo "Removing the current stage environment"
rm -rf ~/webapps/django_stage/lib
rm -rf ~/webapps/django_stage/bellnetwork
# 
# Copy the test to stage
#
echo "Deploying from test to stage"
cp -r ~/webapps/django_test/lib         ~/webapps/django_stage/lib
cp -r ~/webapps/django_test/bellnetwork ~/webapps/django_stage/bellnetwork
rm ~/webapps/django_stage/bellnetwork/settings_dev.py

The first time I ran this, it behaved as expected, but every other time the settings_dev.py is not copied. Each time I run this script I get a 'No such file or directory' error on the rm command. Like I said this works and it ultimately shouldn't be in the destination directory but I'd like to understand why it's not being copied.

Any suggestions?

asked 18 Jun '11, 21:31

Rupe
411814
accept rate: 0%


Perhaps adding logic to check if the file exists will help,

if [ -f ~/webapps/django_stage/bellnetwork/settings_dev.py ]
then
   echo "removing settings_dev.py"
   rm ~/webapps/django_stage/bellnetwork/settings_dev.py
fi
permanent link

answered 18 Jun '11, 21:46

johns
5.4k312
accept rate: 23%

I thought about that, but that doesn't explain why it's not copied. I just want to make sure everything is being copied as expected.

(18 Jun '11, 21:48) Rupe

If it works the first time but not after that than perhaps it is being removed the first time and thus does not exist the second time, You will have to look with 'ls' and might even add 'ls' to parts of the script to get more info.

(18 Jun '11, 21:57) johns

This could be related to the file already existing, in which case the copy command won't automatically overwrite the existing file. One could use the -f flag to "force" the operation, but john's solution is better overall. (Also, another relevant option that performs similarly is the "--remove-destination" flag.)

(18 Jun '11, 22:00) ryans ♦♦

Ok, so it was deleted from the source. It must have been from a flawed iteration of the copy script.

(18 Jun '11, 22:27) Rupe
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×25
×23
×16

question asked: 18 Jun '11, 21:31

question was seen: 2,327 times

last updated: 18 Jun '11, 22:27

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM