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
With the Z-Shell:
set -- *(*Nom[1]);[[ "$1" != "$prev" ]]&&./"$1";prev="$1"
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
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
I said zsh(not bash!).
Try it with zsh and cd to the directory first:
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.
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.
With the Z-Shell (only!):
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