Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an Ubuntu 10.04 OS, and if I do this on the terminal (it works):

$ ssh new_machine "find /tmp/test_*.csv -mtime +14 -exec rm '{}' \;"

But if I place it in a shell script, it does not work. I suspect it is related to the "*" wildcard. Any thoughts on doing this?

share|improve this question

1 Answer 1

You don't want globbing at all, you want find to be doing that. I think this might work:

$ ssh new_machine "find /tmp -name 'test_*.csv' -mtime +14 -exec rm '{}' \;"

share|improve this answer
    
I just checked it and there are no files on the local machine. I am sending the command via ssh to the new_machine... –  Carmen Oct 29 '10 at 18:55
1  
I got it backwards, you don't want to glob at all. Take a look at the edited answer. –  Andrew Oct 29 '10 at 18:56
    
Interesting. That works. Can you explain why my original command was not working? What was happening to my wildcard? –  Carmen Oct 29 '10 at 19:18
    
I'm not entirely sure, but I suspect that absolutely nothing was happening to it. The find command doesn't run in a shell when you invoke it via ssh. So there's nothing to expand the wildcard except find itself, and it may not do that on that argument. Try ssh new_machine "echo /tmp/test_*.csv" and see if you get what you expect. –  Andrew Oct 29 '10 at 19:28
    
@Carmen: When you run the command without the quotes, the shell expands the wildcard in /tmp/test_*.csv. Normally the expansion is the list of matching file names, but if there happens to be no matching file, then the expansion is the single word /tmp/test_*.csv, as if there had been quotes, so only then does find see the argument you meant. –  Gilles Oct 30 '10 at 0:14

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.