Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cp command won't run if executed from shell script

Tags:

linux

bash

shell

cp

i have very simple shell script

#!/bin/bash    
cp -rf /var/www/ksite/app2/* /var/www/ksite/app
echo "----"
echo "done"

but seems cp command fails

if i execute

cp -rf /var/www/ksite/app2/* /var/www/ksite/app

from terminal everything work ok. Can someone tell me how to include cp in shell script?

Thanks

like image 969
Kupe3 Avatar asked Dec 27 '22 22:12

Kupe3


1 Answers

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:

  1. On the command line (which works), do a which cp
  2. Whatever the reply, then copy that and use it as the cp in the script (e.g. /bin/cp)
  3. Check the widcard expansion, run your script with bash -x script-name and see if you get what you expect.
  4. echo $? after the copy in the script - if it is zero then it (thinks it) worked.
  5. Do a ls -ld /var/www/ksite/app from your script, maybe someone set a symbolic link?
  6. If it still fails, source the script from the command-line and see if that works . script-name
  7. Double check that the copy did actually fail! (maybe that should be step 1.)
like image 87
cdarke Avatar answered Jan 06 '23 08:01

cdarke