cp command won't run if executed from shell script
We seem to have doubt as to how this script fails. If there is no error message then this is a strange one. I suggest:
- On the command line (which works), do a
which cp
- Whatever the reply, then copy that and use it as the
cp
in the script (e.g./bin/cp
) - Check the widcard expansion, run your script with
bash -x script-name
and see if you get what you expect. echo $?
after the copy in the script - if it is zero then it (thinks it) worked.- Do a
ls -ld /var/www/ksite/app
from your script, maybe someone set a symbolic link? - If it still fails, source the script from the command-line and see if that works
. script-name
- Double check that the copy did actually fail! (maybe that should be step 1.)
I had similar problem. What helped me:
I used windows and putty to write script, so I had \r\n at the end of lines. Be sure, you have only \n symbol.
I copied files and the only way it worked for me at script was
cp <source_dir>/fileName <dest_dir>/fileName
whereas at command linecp <source_dir>/fileName <dest_dir>
worked well too.