Sponsored Content
Top Forums Shell Programming and Scripting How to get the exit code of -exec in the find command Post 302357194 by oku on Tuesday 29th of September 2009 07:53:14 AM
Old 09-29-2009
Quote:
Originally Posted by rdcwayx
-cmin -100 is mean less than 100 minutes, not 100 seconds.

find with -exec will be used as below format, but I don't see the part of {} \; in your script.

Code:
find . -exec ls -l {} \;

Yes 100 mins is correct.

Does this part make any difference? The command itself works that I know. But when I try to make it fail, I don't get another exit code.

---------- Post updated at 01:53 PM ---------- Previous update was at 10:11 AM ----------

What I have tried so far:

It came up in my mind, that this could work like a pipe. I found an information, that the exitcode of the first command in a pipe could get read (in a bash) by {$PIPESTATUS[0]}, the second command of the pipe by {$PIPESTATUS} and so on. But unfortunately it doesn't work in that case... Smilie
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies

2. UNIX for Dummies Questions & Answers

find command exec error

Hi All, i am writing a shell script in korn shell which deletes all the files in a directory once in every 10DAYS. the directory has different format files. the script has something like this; cd /home/data/pavi echo "Please Enter the Number of Days to search for" read DAYS... (2 Replies)
Discussion started by: pavan_test
2 Replies

3. UNIX for Advanced & Expert Users

Find command with prune and exec

Hi, I'm using the following command to get a list of files on the system. find /releases -type f -exec ls -l > /home/sebarry/list.txt '{}' \; however, its searching a directory I don't want it to search so I know I have to use prune but I don't seem to be able to get prune and exec to work... (1 Reply)
Discussion started by: Sebarry
1 Replies

4. Shell Programming and Scripting

find command with -exec

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 (2 Replies)
Discussion started by: max29583
2 Replies

5. Shell Programming and Scripting

find command with -exec

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... (12 Replies)
Discussion started by: jonnyd
12 Replies

6. UNIX for Dummies Questions & Answers

What does the '\' in find -exec command

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... (3 Replies)
Discussion started by: Grueben
3 Replies

7. UNIX for Dummies Questions & Answers

[Solved] weird in find -exec command

i feel weird with this 2 command find /tmp/*test* -user `whoami` -mtime +1 -type f -exec rm -f {}\; find /tmp/*test* -user `whoami` -mtime +1 -type f -exec ls -lrt {}\; the first one return correct which only delete those filename that consist *test* where second command it listed all the... (12 Replies)
Discussion started by: lsy
12 Replies

8. Shell Programming and Scripting

Find and move command with exec

Hi all, I am trying to find files newer than a given file and them mv them to a new location. So I far I have: find . ! -newer <file_name> -exec ls -l {} \; and find . ! -newer <file_name> -exec mv /TEMP_LOCATION {} \; find is not liking this. Anyone know how to modify the last... (2 Replies)
Discussion started by: jonnyd
2 Replies

9. 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
SyncExec(3pm)						User Contributed Perl Documentation					     SyncExec(3pm)

NAME
Proc::SyncExec - Spawn processes but report exec() errors SYNOPSIS
# Normal-looking piped opens which properly report exec() errors in $!: sync_open WRITER_FH, "|command -with args" or die $!; sync_open READER_FH, "command -with args|" or die $!; # Synchronized fork/exec which reports exec errors in $!: $pid = sync_exec $command, @arg; $pid = sync_exec $code_ref, $cmd, @arg; # run code after fork in kid # fork() which retries if it fails, then croaks() if it still fails. $pid = fork_retry; $pid = fork_retry 100; # retry 100 times rather than 5 $pid = fork_retry 100, 2; # sleep 2 rather than 5 seconds between # A couple of interfaces similar to sync_open() but which let you # avoid the shell: $pid = sync_fhpopen_noshell READERFH, 'r', @command; $pid = sync_fhpopen_noshell WRITERFH, 'w', @command; $fh = sync_popen_noshell 'r', @command_which_outputs; $fh = sync_popen_noshell 'w', @command_which_inputs; ($fh, $pid) = sync_popen_noshell 'r', @command_which_outputs; ($fh, $pid)= sync_popen_noshell 'w', @command_which_inputs; DESCRIPTION
This module contains functions for synchronized process spawning with full error return. If the child's exec() call fails the reason for the failure is reported back to the parent. These functions will croak() if they encounter an unexpected system error, such as a pipe() failure or a repeated fork() failure. Nothing is exported by default. fork_retry [max-retries [sleep-between]] This function runs fork() until it succeeds or until max-retries (default 5) attempts have been made, sleeping sleep-between seconds (default 5) between attempts. If the last fork() fails fork_retry croak()s. sync_exec [code] command... This function is similar to a fork()/exec() sequence but with a few twists. sync_exec does not return until after the fork()ed child has already performed its exec(). The synchronization this provides is useful in some unusual circumstances. Normally the pid of the child process is returned. However, if the child fails its exec() sync_exec returns undef and sets $! to the reason for the child's exec() failure. Since the @cmd array is passed directly to Perl's exec() Perl might choose to invoke the command via the shell if @cmd contains only one element and it looks like it needs a shell to interpret it. If this happens the return value of sync_exec only indicates whether the exec() of the shell worked. The optional initial code argument must be a code reference. If it is present it is run in the child just before exec() is called. You can use this to set up redirections or whatever. If code returns false no exec is performed, instead a failure is returned using the current $! value (or EINTR if $! is 0). If the fork() fails or if there is some other unexpected system error sync_exec croak()s rather than returning. sync_fhpopen_noshell fh type cmd [arg]... This is a popen() but it never invokes the shell and it uses sync_exec() under the covers. See "sync_exec". The type is either 'r' to read from the process or 'w' to write to it. The return value is the pid of the forked process. sync_popen_noshell type cmd arg... This is like sync_fhpopen_noshell, but you don't have to supply the filehandle. If called in an array context the return value is a list consisting of the filehandle and the PID of the child. In a scalar context only the filehandle is returned. sync_open fh [open-spec] This is like a Perl open() except that if a pipe is involved and the implied exec() fails sync_open() fails with $! set appropriately. See "sync_exec". Like sync_exec, sync_open croak()s if there is an unexpected system error (such as a failed pipe()). Also like sync_exec, if you use a command which Perl needs to use the shell to interpret you'll only know if the exec of the shell worked. Use sync_fhpopen_noshell or sync_exec to be sure that this doesn't happen. AUTHOR
Roderick Schertler <roderick@argon.org> SEE ALSO
perl(1). perl v5.8.8 2005-02-04 SyncExec(3pm)
All times are GMT -4. The time now is 01:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy