3

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.

2
  • 1
    Give a minimal example that fails for you. Nov 11, 2011 at 19:11
  • To be clear, you actually have a file called /tmp/mnt221234jk/*?! Really? Nov 12, 2011 at 6:13

3 Answers 3

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.

3

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!

1
  • That's the answer I was looking for! Quick and working!
    – alex
    May 16, 2015 at 15:45
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .