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.

I'm working on making some scripts more elegant by implementing them in a real x application etc...

At some point in the scripts we basically want to take everything from a mounted removable storage device, and copy into specified folder in a tmp work folder. When executing in the shell it works without a hitch. When executed from the code, it fails.

Copy Command:

cp -avfr /tmp/mnt221234jk/* /tmp/mnt23255/disk1/

and the error I get from native app is:

cp: cannot stat: '/tmp/mnt221234jk/*' file not found.

The strange part is that it is absolutely there, has appropriate permissions for the user running the app etc. I can both stat /tmp/mnt221234jk/* and run the cp command from the shell and both work just fine.

In addition to this, if I omit the /* from the file copy origin, it works, but creates a new folder in the destination with name mnt221234jk which is not what I am looking for.

A couple of side notes: my code to execute shell commands absolutely works, and works well. But there very well may be something funky about needing work paths or something like that.

Does failing to stat based on file not existing error ring any bells with anyone?

I'd be willing to attempt to achieve this differently if there are alternative shell commands to effectively copy a file structure recursively with permissions etc.

share|improve this question
1  
Give a minimal example that fails for you. –  Faheem Mitha Nov 11 '11 at 19:11
    
To be clear, you actually have a file called /tmp/mnt221234jk/*?! Really? –  David Schwartz Nov 12 '11 at 6:13

3 Answers 3

The call in the script where you're having the problem isn't globbing the files, but the shell does. I'm not quite clear on how you're calling it, but you'll need to either find a way to glob or loop over the files.

share|improve this answer

There's a bug in your script. We can't tell where because you haven't shown your script.

Given your limited description, it seems that the shell is not expanding /tmp/mnt221234jk/* to a list of files, even though the cp command, which is running with the same privileges, can traverse the directory. So a likely explanation is that you've turned off globbing with set -f or set -o noglob at some point. Turn in back on with set +f.

share|improve this answer

Well I apologize in advance, the real problem was actually really quite simple... it was a problem with globbing files, but not because my shell had explicitly disabled it, or relative pathing.

I was launching "shell scripts" and shell commands but outside the context of bash/sh/tcsh etc. Executing cp directly is gonna just be problematic as far as that goes.

Executing

/bin/bash -c "cp /blah/* /someotherdir/"

worked fantastically. Appreciate the clues!

share|improve this answer

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.