Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

ssh server ls /var/lib/edumate/backup/weekly/*DBB* returns one file

/var/lib/edumate/backup/weekly/DBB.0.db2inst1.NODE0000.CATN0000.20120610020013.001 

but ssh server ls /data/backup/weekly/*DBB* returns what is in mounted linked directory

/data/backup/weekly/DBB.0.db2inst1.NODE0000.CATN0000.20120513020022.001
/data/backup/weekly/DBB.0.db2inst1.NODE0000.CATN0000.20120520020018.001
/data/backup/weekly/DBB.0.db2inst1.NODE0000.CATN0000.20120527020019.001
/data/backup/weekly/DBB.0.db2inst1.NODE0000.CATN0000.20120603020028.001
/data/backup/weekly/DBB.0.db2inst1.NODE0000.CATN0000.20120610020013.001
/data/backup/weekly/DBB.0.db2inst1.NODE0000.CATN0000.20120710120854.001

Where /data is on another partition

/dev/sdb2 on /data type ext3 (rw,acl,user_xattr)

and backup is a symlink to /data/backup

lrwxrwxrwx 1 root     root       12 Jul 10 14:27 backup -> /data/backup/

Of course I am after the list of files from the mounted/linked directory. Is there any way how I can use /var/lib/edumate/backup in ls and not the linked one? Is scp going to behave the same?

share|improve this question
1  
On your client, from which you are executing the ssh command, change to your home directory and try again. I suspect a globbing issue. –  Michael Hampton Jul 13 '12 at 0:28
    
hm, in fact I run it as php user through sudo from php script. But I tried from command line as php user too. I tried to changed to home dir of php user as you suggested and it worked. Now it works even from the php script (where I don't change to home dir. Any explanation? –  Radek Jul 13 '12 at 0:35

1 Answer 1

up vote 9 down vote accepted

My best guess is that on your client machine, from which you ran ssh, that you also have a directory named /var/lib/edumate/backup/weekly. At the time you ran it, that directory on your client machine contained only the one file. But now it contains all the files you expect.

What happens is that the wildcard matching happens on the client machine rather than on the server. And at the time, there was probably only the one file there. Thus, what the server would have received from your command was:

ls /var/lib/edumate/backup/weekly/DBB.0.db2inst1.NODE0000.CATN0000.20120610020013.001

To prevent this in the future, run the command with quotes, such as:

ssh server ls "/var/lib/edumate/backup/weekly/*DBB*"

The wildcards will then be passed on to the server instead of being expanded by your shell on the client machine.

share|improve this answer
    
You're right that the same directory is on the client's system. But it's empty. One level up (still on a client's computer) is sitting a file that I was probably getting as a result from remote host. But know from whatever directory I do ssh the correct result is returned. –  Radek Jul 13 '12 at 1:01
    
The file is no longer there, then. Or you mistyped it earlier and wound up with its actual location by mistake. In either case, putting the filename in quotes will prevent it from happening again. –  Michael Hampton Jul 13 '12 at 1:02
    
I use the same command to be executed on the command line (I didn't type it - echoed from php and copied). And I didn't delete any file on the file system. So nothing you say applies. –  Radek Jul 13 '12 at 1:35
    
In that case, you have gremlins in your system, and there's not much I can do beyond what I've already done. :) –  Michael Hampton Jul 13 '12 at 1:43
1  
This answer is actually correct, or mostly so. The fact is that your glob pattern *DBB* is expanded by your local shell, and whatever it's expanded to is passed to ssh. If you want it to be expanded by the remote shell it must be quoted. –  bahamat Jul 13 '12 at 2:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.