Execute multiple commands in a find


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute multiple commands in a find
# 1  
Old 01-05-2009
Execute multiple commands in a find

I am checking that a file is older than a reference file that I build with a touch command before processing it. If it is not old enough, I want to sleep for an hour and check again.

My problem is if it is old enough to process, I want to exit when I am done, but I cannot find a way to exit after doing a successful find. It keeps looping and processing until the count is fulfilled. I have tried doing an exit as a -exec on the find as shown below and I have tried checking the status of the find with $?, but it is always "0" whether the file is old or new.

Any ideas?

Code:
typeset -i  count=1

while ((${count} <= 3))
do
 find  /export/home/MYACCT/ -type f -name \ar5.log ! -newer /WORKDIR/REF -exec /export/home/MYACCT/datetest.ksh \; -exec exit 0 \;
   count=${count}+1
   sleep 3600
done

echo "No file to process"
exit 5

# 2  
Old 01-05-2009
You can try putting the output of the find command into a variable and then checking to see if the variable value is empty or not.
Padow
# 3  
Old 01-05-2009
Thanks

Thanks Padow, that worked great.

Code:
abc=`find  /export/home/MYACCT/ -type f -name \ar5.log ! -newer /WORKDIR/REF`

if [ -z "$abc" ]; then
   count=${count}+1
   sleep 3600
else
  /export/home/MYACCT/datetest.ksh
  exit 0
fi
done

echo "No file to process"
exit 5

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh multiple hops to execute commands with arguments

Hi I need to write a script to ssh through several hops (e.g. HostA-HostB-HostC-HostD), where Host A does not have direct assess to HostC ; HostB cannot access HostD directly. when I ssh 3 hops and run command with arg1, arg2 and redirect the output to a file, e.g. HostA> ssh -t HostB ssh -t... (3 Replies)
Discussion started by: chiensh
3 Replies

2. Shell Programming and Scripting

Using sed to execute multiple commands

Let's say I have a file called test.out. In this file I want to do the following: 1. Search for DIP-10219 and with this: 2. Remove everything in front of cn= 3. Remove everything after *com 4. Remove duplicate lines 5. Replace ( with \( 6. Replace ) with \) For 1-3 I have figured out this... (11 Replies)
Discussion started by: exm
11 Replies

3. Shell Programming and Scripting

How to execute multiple commands in one shot?

for example: I'm greping the process where i can get the location of the file $ ps -ef | grep LLAWP | awk {'print $9'} | tail -1 /Hostname/ihs/INSTANCE2/conf/WebAgent.conf then I need to display second line of WebAgent.conf file: $ cat /Hostname/ihs/INSTANCE1/conf/WebAgent.conf | head... (2 Replies)
Discussion started by: raghur77
2 Replies

4. UNIX for Dummies Questions & Answers

Using find -exec with multiple commands :(-

Hi all, Am wanting to do a ls -l of the files and do a cat of it at the same time, ideally, I am hoping that the following work but obvisouly it is not working to what I am wanting it to ... hu hu hu :wall: find . -name "BACKUP_TIMESTAMP.log" -exec "ls -l basename {} ; cat {}" \; ... (1 Reply)
Discussion started by: newbie_01
1 Replies

5. Shell Programming and Scripting

connect to multiple servers using SSH and execute commands

Requirement: Run a shell script with below inputs file name checksum path the script should go to multiple servers (around 35) and verify the input cksum and if there is a mismatch display a simple message to the user that cksum verification failed. host details, user id /... (1 Reply)
Discussion started by: amicableperson
1 Replies

6. Shell Programming and Scripting

Find and execute shell scripts in multiple sub directories in parallel

I have one parent directory and within that parent directory there are several other sub-directories and within those sub-directories there are several other "large number" of sub-directories. All the sub directories have a shell script in them with a common file name execute_command.sh I want... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

7. UNIX for Dummies Questions & Answers

cron used to execute multiple commands

have to run multiple commands at a specified time by the user... (3 Replies)
Discussion started by: hemaa
3 Replies

8. UNIX for Advanced & Expert Users

How to execute multiple unix commands in one session from java

Hi, Iam trying to code in java and wanted to run the commands in the Unix remote servers. I have the following code to run multiple GREP commands in a single session. But when i execute this, the first command executes successfully, whereas from the next line it says "Exception Occured... (1 Reply)
Discussion started by: gravi2020
1 Replies

9. Shell Programming and Scripting

Can Xargs execute multiple commands of evry input file

Hello , I am trying to print the footer of evry file in the given directory with xargs command like follows ls -1 | xargs -I {} gzcat {} | tail -1 now problem with this is only last file foooter is getting printed as " | tail -1 " is getting executed for the last file. I know this can... (4 Replies)
Discussion started by: nilesrex
4 Replies

10. Shell Programming and Scripting

how do i get my script to execute multiple commands?

New to shell scripting. I can't get my script to execute multiple commands. Here's the code. It's a menu script. #!/bin/ksh clear print "SDE MENU" PS3="SDE MENU, enter choice:" select clean_menu in "tasdedev instance 5151" "orkindev instance 5155" "tasdetst instance 5157" "orkinsys... (1 Reply)
Discussion started by: hvincent
1 Replies
Login or Register to Ask a Question