Need help with -exec cp command.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need help with -exec cp command.
# 29  
Old 09-09-2008
The non-absolute paths were from my example - not his. Sorry for adding to the confusion, Bakunin
# 30  
Old 09-09-2008
Quote:
Originally Posted by bakunin
This sure looks weird.

To sum up what we know so far:

OS: RedHat
Shell: bash
User: root
no chrooted environment, no special non-printing characters.

First observation: the paths in the script are not absolute paths. This might lead to no directories/files being found when the script is executed in a wrong current path. Change these paths to absolute paths to make the script more robust.

Here is another take at problem determination: modify your script by switching on printing of the interpreted lines:

Code:
#!/bin/bash

set -xv      # <--- makes every line being printed to stdout after parsing

fRootDir="/some/path"   # set an absolute starting path

find $fRootDir/dir1/dir2 -type f -name "FILE.*" -newer $fRootDir/dir1/dir2/afterme.txt -exec cp {} $fRootDir/dir1/dir2/dir3 \;

exit 0

Now start the script this way:

Code:
root@server # ./myscript.sh 2> myscript.log

and post the contents of the file myscript.log here. I would really be interested in what the problem is here and what the final solution will be.

I hope this helps.

bakunin

Contents of myscript.log:

: bad interpreter: No such file or directory
# 31  
Old 09-09-2008
Maybe something is getting lost in the translation from your environment to our sample environment.

Can you easily create a new tree with bogus data like the example that follows:
Code:
mkdir -p /script/dir1/dir2/dir3
touch /script/dir1/dir2/FILE.1 /script/dir1/dir2/FILE.2
touch /script/dir1/dir2/afterme.txt
touch /script/dir1/dir2/FILE.3 /script/dir1/dir2/FILE.4

And then run the script that Bakunin has recommend again with the new directory tree of /script/dir1/dir2

Then, you can copy and paste the actual script that you are using without worrying about exposing any sensitive data.

Failing that, identify which find you are using. Perhaps the libraries for your find utility are corrupted, or use a different set of options than the version of find that shipped with your OS.

edit: As in - more than one version of find installed
# 32  
Old 09-09-2008
Here's the results:

[root@server] /script # more myscript.log

fRootDir="/script" # set an absolute starting path
+ fRootDir=/script

find $fRootDir/dir1/dir2 -type f -name "FILE.*" -newer $fRootDir/dir1/dir2/afterme.txt -exec cp {} $fRootDir/dir1/dir2/dir3 \;
+ find /script/dir1/dir2 -type f -name 'FILE.*' -newer /script/dir1/dir2/afterme.txt -exec cp '{}' /script/dir1/dir2/dir3 ';'

exit 0
+ exit 0
# 33  
Old 09-09-2008
Did you do an ls of /script/dir1/dir2/dir3 to see if FILE.3 and FILE.4 got copied in?
# 34  
Old 09-09-2008
Yes I did, and yes they did. So why does that work and mine doesn't?
# 35  
Old 09-09-2008
I'm guessing that there's a minor typographical error in your script.

Go through it character by character. If you use vi, try
Code:
:set list

to show invisible characters. There may be something funky in there that you can't see.

To turn off the invisibles, do:
Code:
:set nolist

edit: list/nolist does not remove the characters - it simply displays/hides them as appropriate
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Exec command - what is it doing here?

Hi all, Forgive me for asking for help with my first post, but I am struggling here. I've been asked to translate a bash script into a Windows script (probably batch or powershell, not sure yet), so the first step is obviously understand what the bash script is doing. But I have no experience in... (5 Replies)
Discussion started by: el_foz
5 Replies

3. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

4. Shell Programming and Scripting

exec command help

Hi, I have the following lines in a script : . . exec < some_file . . . I have very little idea about exec command. I would like to know what this does and what will happen if the file some_file does not exist. Specifically, I would like to know whether the lines following this... (5 Replies)
Discussion started by: elixir_sinari
5 Replies

5. UNIX for Dummies Questions & Answers

Exec command

Hi can some one explain the following command , It would really help if some can really elloborate on what is happening out here export PATH | exec /bin/sh ./auto_approve :q P.S: This is the first time i am using exec ,so an elloboration what does it do and what is the use of the :q will be... (1 Reply)
Discussion started by: Sri3001
1 Replies

6. Shell Programming and Scripting

exec command

How can I use the exec command to log my korn shell session to the screen and the log file? Currently I have this command: $exec 1> ${LOG} 2>&1 This logs the output to the log file only. I want it to go to the screen also. Is this possible with this command? thanks. (10 Replies)
Discussion started by: djehresmann
10 Replies

7. Shell Programming and Scripting

exec command help

All, I am using below shell script to output the content to outputfile.txt. What I am looking for is in addition to outputfile.txt, I want the output to be on standard output too. exec > outputfile.txt echo "Starting " echo "ending" (5 Replies)
Discussion started by: basic_shell
5 Replies

8. Shell Programming and Scripting

exec command

can any one pls explain the meaning of exec 1<&5 ?? its urgent (2 Replies)
Discussion started by: santosh1234
2 Replies

9. Shell Programming and Scripting

exec command

hai i want know the difference between two shell scripts those are 1) a=2004 echo $a #output------2004 exec < inputfile while read line do echo $a #output-------2004 a=2005 echo $line echo $a ... (1 Reply)
Discussion started by: g_s_r_c
1 Replies

10. UNIX for Dummies Questions & Answers

using the -exec command

linux redhat 8.0 I am getting accustomed to using the -exec command to get around my databse.. and use it to edit and update files..! is this more apllicable than jumping from one directory to the other.. I have set up the databse so that the inode #'s are accessable and can get me from one... (0 Replies)
Discussion started by: moxxx68
0 Replies
Login or Register to Ask a Question