Error copying file using wildcard

Hi,

cd /web/myf
ls -ltr 
-rwxr-x--- 1 user1 Admin    17 Oct  7 15:53 mykey.db
-rwxr-x--- 1 user1 Admin    21 Oct  7 15:53 test.sh

more test.sh

cd log01
pwd
cp ../*.db .

When i run the test.sh i get the below output / error.

Output:

/web/myf/log01
cp: cannot stat `../*.db': No such file or directory

I was expecting /web/myf/mykey.db to be copied to /web/myf/log01/mykey.db

Can you please tell me whats wrong with my code ?

One might guess that /web/myf/log01 is a symbolic link instead of being a directory, but you haven't given us enough information to confirm that guess...

What output do you get from the command:

ls -ld /web/myf/log01

After the cd log01 , you could try the command:

cp /web/myf/*.db .

which should work to copy /web/myf/mykey.db into your current working directory no matter what directory you are sitting in.

/web/myf/log01 is not a symbolic link but a directory i created using mkdir .

The same script needs to run on several environments on several servers so i dont with to hard code the path.

By the way why does cp ../*.db . not work ??

It DOES work. If the source file exists and permissions allow for it.

The error message you see clearly states that the path/file does NOT exist.
Eliminating errors frequently is a tedious task which, to gain insight, best is approached step by step, of which one has been proposed by Don Cragun. If that either works or doesn't, you know the direction into which to dig deeper.

While the file exists as share in the OP and has permissions .... i am clueless as to why the cp is failing ...

ls -ld /web/myf/log01
drwxr-xr-x 2 user1 admin 4096 Jan 17 17:16  /web/myf/log01

There could be something more to this issue ?

Can you show us the screen out whilst you do all of this:-

uname -a
cd /where/you/want/to/be
ls -l ../file/to/copy
ls -ld .
cp ../file/to/copy .

Please paste the whole output in CODE tags for clarity.

Thanks,
Robin