script to find latest executable in particular directory and start that particular ex


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
script to find latest executable in particular directory and start that particular ex

i have a directory in which there are executable files and these files are added at runtime. now i need a shell script which will be called at a certain interval. this shell script should find the latest executable file in that directory and start that executable. care should be taken that once the executable has started the script should not restart again that executable
# 2  
With the Z-Shell:

Code:
set -- *(*Nom[1]);[[ "$1" != "$prev" ]]&&./"$1";prev="$1"

# 3  
hi radoulov,

Could you briefly explain what the script is doing?

i tried running the script which u gave...it gave me the foll errors.....

eaton@ubuntu:~/vineeth/file_handling/executable$ set -- home/eaton/vineeth/file_handling/executable;[[ "$1" != "$prev" ]]&&./"$1";prev="$1"
-bash: ./home/eaton/vineeth/file_handling/executable: No such file or directory
# 4  
CPU & Memory Hello

Replace ".sh" with your own extention or leave it if the directory have only scripts.

ls -lrt|grep ".sh"|tail -1|awk '{print $9}' > file1
for i in `cat file2`
do
cat file1|grep -v $i > file3
sh `cat file3`
cp file1 file2
done
# 5  
Quote:
Originally Posted by kvineeth
hi radoulov,

Could you briefly explain what the script is doing?

i tried running the script which u gave...it gave me the foll errors.....

eaton@ubuntu:~/vineeth/file_handling/executable$ set -- home/eaton/vineeth/file_handling/executable;[[ "$1" != "$prev" ]]&&./"$1";prev="$1"
-bash: ./home/eaton/vineeth/file_handling/executable: No such file or directory
I said zsh(not bash!).
Try it with zsh and cd to the directory first:
Code:
zsh
cd /home/eaton/vineeth/file_handling/executable
while :;do
set -- *(*Nom[1]);[[ "$1" != "$prev" ]]&&./"$1";prev="$1"
sleep 300
done

Adjust the sleep interval for your needs.
# 6  
let me be more clear what exactly i require....

i have a directory which will contain executable code...eg

eaton@ubuntu:~/vineeth/file_handling/executable$ ls -l
total 24
-rwxr-xr-x 1 eaton eaton 8757 2003-02-03 18:49 a.out
-rwxr-xr-x 1 eaton eaton 8757 2003-02-03 18:49 file_dup

now in this directory more executable code can be put at run time..i have to find out which which is the latest one that has been added to this directory and that file has to be started by the script. if it is the first time the script starts then it should start all the executable present in the directory...but after that only the latest..no repition of the same executable.
# 7  
With the Z-Shell (only!):

Code:
cd <your_executables_dir>
unset prev firsttime
 while :;do
	[ "$firsttime" ]||{ 
					set -- *(N*)
					for i;do 
						print "Starting $i ..."
						./"$i"
					done
					firsttime=y
					prev="$@[-1]"
				} 
sleep 10
set -- *(*Nom[1])
[[ "$1" != "$prev" ]]&&{ 
					print "Previous is $prev, starting $1 ..." 
					./"$1"
					prev="$1" 
				}
done

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #177
Difficulty: Easy
The Apple Computer Company was founded on April 1, 1976.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find exit with success with non executable directory

Hi there, I'm quite surprised by the following behavior of find. $ find -ls # I have a directory and a file in it 8145 4 drwxr-xr-x 3 me me 4096 May 10 09:36 . 87 4 drwxr-xr-x 2 me me 4096 May 10 09:36 ./dir 88 0 -rw-r--r-- 1 me me 0... (2 Replies)
Discussion started by: chebarbudo
2 Replies

2. Shell Programming and Scripting

Help with korn shell script to get the latest file versions in a directory

I want to write a korn shell script to get the latest three versions for a file in the directory having lot of files with various versions (files with prefix as same but time stamp as suffix) and compress it and at the same time have to remove the remaining versions of the file (other than latest... (4 Replies)
Discussion started by: maheshbabu
4 Replies

3. UNIX for Dummies Questions & Answers

To find the latest modified file in a directory

I am trying to fetch the latest modified file from a directory using the command find . -type f -exec ls -lt \{\} \+ | head | awk '{print $9}' After the O/P, I get the below mentioned error and the command doesnt terminate at all. find: ls terminated by signal 13 find: ls terminated by... (2 Replies)
Discussion started by: Sree10
2 Replies

4. Shell Programming and Scripting

Script to move latest zip file to another directory

Hi folks, In my application there is a job running which create a .dat file along with it zip file also at unix box location /opt/app/cvf/temp1 so in temp1 directory I have one .dat file and its zip file also. Now since this job runs every day so if a job runs today there will be two files... (5 Replies)
Discussion started by: punpun66
5 Replies

5. Shell Programming and Scripting

Find the latest directory and loop through the files and pick the error messages

Hi, I am new to unix and shell scripting,can anybody help me in sctipting a requirement. my requirement is to get the latest directory the name of the directory will be like CSB.monthdate_time stamp like CSB.Sep29_11:16 and CSB.Oct01_16:21. i need to pick the latest directory. in the... (15 Replies)
Discussion started by: sudhir_83k
15 Replies

6. Shell Programming and Scripting

find the latest files in multiple directory

I want to get the latest files from multiple directories, d1, d2,d3 and d4 under the parent dierectoy d. can anyone help out with this? thx (3 Replies)
Discussion started by: shyork2001
3 Replies

7. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

8. Shell Programming and Scripting

script to find filenames with latest version and for all seq. numbers in a day

Hi, We have a requirement to find the set of filenames from the group of files in a specified folder based on (i) version number (ii) sequence number such that, for any given sequence number in a day only the latest version filenames have to indentified. Below is the format of... (4 Replies)
Discussion started by: Deepakbabu
4 Replies

9. UNIX for Dummies Questions & Answers

Script to find a string in a directory/sub-directory

I'm trying to find this string 'preparing string IBE_Quote_W1_Pvt.SaveWrapper for quote_header_id’ in my Apache log file directory. The log file that contains this string may be in a parent direcotry or a sub-directory. I have tried 'grep' and 'awk' with no success. I would like to get the path... (3 Replies)
Discussion started by: gross
3 Replies

10. Shell Programming and Scripting

shell script to find latest date and time of the files

Hi everyone, Please help:) I have a list of 1000 different files which comes daily to the directory.Some of the files are not coming to the directory now. I need to write a shell script to find the latest date and time of the files they came to the directory. The files should be unique.... (1 Reply)
Discussion started by: karthicss
1 Replies

Featured Tech Videos