Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


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


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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 :

Code:
 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 return the following in the console screen :

Code:
/home/user_install/.bashrc
/home/user_install/.profile
/home/user_install/.i18n
/home/user_install/.inputrc
/home/user_install/.gtkrc-2.0

Within that script the function 'COPY_CHERCHE ' is define as this :

Code:
function COPY_CHERCHE () {

    local B_FILE
    local B_FOLDER_OUT
    local B_EXCLUDE
    local B_FILE_OUT
    local MY_DEBUG=1
    FLAG="0"

#    set -x

    B_FILE="$1"
    B_FOLDER_OUT="$2"
    B_EXCLUDE="$3"
    B_FILE_OUT="$4"
    echo "B_FILE        : $B_FILE"
    echo "B_FOLDER_OUT  : $B_FOLDER_OUT"
    echo "B_EXCLUDE     : $B_EXCLUDE"
    echo "B_FILE_OUT    : $B_FILE_OUT"

# +-------------+
# |    BEGIN    |
# +-------------+

    echo
    echo "--"
    echo

# +-----------+
# |    END    |
# +-----------+

}

export -f COPY_CHERCHE

Now we change the test command with the real command :
Code:
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'    -exec bash -c 'COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___17:23:39     ¤    /tmp/000_skel_file_list_2019-04-07___17:23:39  '  \;

As tou can see, 4 parameters are sent to the function :

Parameter 1 : the file found by the find command --> "{}"
Parameter 2 : a folder name where to copy the founded file
parameter 3 : the character '¤' which is just flag
parameter 4 : a file where to log operations


My problem is that only one file is taken into account : ''/home/user_install/.inputrc"


Here is my debug output :
Code:
!
! +-+-+-+-+-+-+ ENTERING FUNCTION CHERCHE +-+-+-+-+-+-+
!
PATH         :  /home/user_install   -maxdepth 1    -type f 
SEARCH       :  -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' 
DATE         :   -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end  
EXCLUDE      :  ¤ 
EXCLUDE DIR  : 
FOLDER OUT   :  /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41 
FILE OUT     :  /tmp/000_skel_file_list_2019-04-07___18:21:41 
!
! COMMAND LINE : 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'    -exec bash -c 'COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41     ¤    /tmp/000_skel_file_list_2019-04-07___18:21:41  '  \; 
!
!


+ eval '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'\''    -exec bash -c '\''COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41     ¤    /tmp/000_skel_file_list_2019-04-07___18:21:41  '\''  \; '
++ 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 -exec bash -c 'COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41     ¤    /tmp/000_skel_file_list_2019-04-07___18:21:41  ' ';'
%
% +-+-+-+-+-+-+ ENTERING FUNCTION COPY_CHERCHE +-+-+-+-+-+-+
%
+ B_FILE=/home/user_install/.inputrc
+ B_FOLDER_OUT=/tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41
+ B_EXCLUDE=¤
+ B_FILE_OUT=/tmp/000_skel_file_list_2019-04-07___18:21:41
+ echo 'B_FILE        : /home/user_install/.inputrc'
B_FILE        : /home/user_install/.inputrc
+ echo 'B_FOLDER_OUT  : /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41'
B_FOLDER_OUT  : /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41
+ echo 'B_EXCLUDE     : ¤'
B_EXCLUDE     : ¤
+ echo 'B_FILE_OUT    : /tmp/000_skel_file_list_2019-04-07___18:21:41'
B_FILE_OUT    : /tmp/000_skel_file_list_2019-04-07___18:21:41
+ echo %
%
+ echo '% +-+-+-+-+-+-+  EXITING FUNCTION COPY_CHERCHE  +-+-+-+-+-+-+'
% +-+-+-+-+-+-+  EXITING FUNCTION COPY_CHERCHE  +-+-+-+-+-+-+
+ echo %
%
+ echo '% +-+-+-+-+-+-+  RETURNING TO FUNCTION CHERCHE  +-+-+-+-+-+-+'
% +-+-+-+-+-+-+  RETURNING TO FUNCTION CHERCHE  +-+-+-+-+-+-+
+ echo %
%
+ echo '!'
!
+ echo '! +-+-+-+-+-+-+ EXITING FUNCTION CHERCHE +-+-+-+-+-+-+'
! +-+-+-+-+-+-+ EXITING FUNCTION CHERCHE +-+-+-+-+-+-+
+ echo '!'
!
+ echo '! +-+-+-+-+-+-+    RETURNING TO MAIN    +-+-+-+-+-+-+'
! +-+-+-+-+-+-+    RETURNING TO MAIN    +-+-+-+-+-+-+
+ echo '!'
!
+ echo '   --- FINISHED ---'
   --- FINISHED ---

Any help is welcome
# 2  
The default between two conditional arguments like -type f or -name xyz is AND.
You can explicitely write -type f -a -name xyz.
The AND makes it necessary to evaluate the second condition if the first condition evaluated TRUE.
The AND has precedence over the -o OR.
If you want to evaluate an OR before an AND you need to work with parenthesis (that must be quoted to escape their special meaning in the shell).
Code:
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'  \)  -exec ...

This User Gave Thanks to MadeInGermany For This Post:
# 3  
Adding -print to the end of your test command, would allow you to more accurately see when the -exec argument would be invoked.

Code:
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' \
       -print

vrs

Code:
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' \) \
       -print

These 2 Users Gave Thanks to Chubler_XL For This Post:
# 4  
Thank you every body for helping.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
What does the '\' in find -exec command
Grueben
Hi, I have two scripts that remove files. One works fine and is coded find -name "syst*" -mtime +1 -exec rm {} \; The other is almost the same - only thing missing is the '\'. On that script though I keep getting: rm syst1202.file ? etc Does the \ make that difference or is it a...... UNIX for Dummies Questions & Answers
3
UNIX for Dummies Questions & Answers
find command with -exec
jonnyd
Hi all, Please could someone help with the following command requirement. I basically need to find files NEWER than a given file and order the result on time. My attempt so far is as follows: find . -newer <file_name> -exec ls -lrt {} ;\ But I dont seem to get the right result...... Shell Programming and Scripting
12
Shell Programming and Scripting
Help! Paste Multiple SQL output result to exec command
jackyntk
Hi, I want to write the shell script to change multple file name (the file name is get from DB) e.g. cp db1.txt file1_new.txt cp db2.txt file2_new.txt cp db3.txt file3_new.txt I have write the script like this: VAR=`sqlplus -s $LOGON @<<ENDOFTEXT set termout off ...... Shell Programming and Scripting
0
Shell Programming and Scripting
find command with -exec
max29583
Hi People, I have a directory full of compressed files (.Z extention) In many of these files there is a string pattern (3800078163033) I want to find all file names which contain this string in their text. Regards, Abhishek... Shell Programming and Scripting
2
Shell Programming and Scripting

Featured Tech Videos