check the file every 15 seconds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check the file every 15 seconds
# 1  
Old 06-24-2005
check the file every 15 seconds

Hi All,

I need a script which does,

script check a file every 15 second, if file not exist, it will create a log file.
how can I do it ?

thanks

Alice
# 2  
Old 06-24-2005
Check this post

https://www.unix.com/shell-programming-and-scripting/19676-loop-through-files-directory.html

Minor modifications would be needed tho'.

Vino
# 3  
Old 06-24-2005
hi,

how abt this

while [ 1 ]
do
if [ ! -f <filename> ]
then
touch <filename>.log
fi
sleep 15
done

-------------------
# 4  
Old 06-24-2005
Quote:
Originally Posted by matrixmadhan
hi,

how abt this

while [ 1 ]
do
if [ ! -f <filename> ]
then
touch <filename>.log
fi
sleep 15
done

-------------------
You dont actually need the if..fi. Just an improvement over your solution.


Code:
#! /bin/sh
while true
do
[[ ! -f <filename> ]] && touch <filename>.log
sleep 15
done

Vino
# 5  
Old 06-24-2005
Quote:
Originally Posted by vino
You dont actually need the if..fi. Just an improvement over your solution.


Code:
#! /bin/sh
while true
do
[[ ! -f <filename> ]] && touch <filename>.log
sleep 15
done

Vino
for the solution offered, the short form of the if test statement suffices ... however, the if-then-fi form actually gives you more flexibility when you have complex requirements for the conditions you're testing for ... especially for somebody just starting out on scripting, i would strongly advise scripters to stick to the if-then-fi form until more proficient or unless only looking for a very short script ... the if-then-fi form is also a lot more readily understandable than the short "[cond]" form ...
Code:
if [ cond ]
then
    while [ cond ]
    do
        if [ cond ]
        then
              commands
        else
             for stuff in list
             do
                  commands
             done
        fi
    done
else
     commands
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Getting files through find command and listing file modification time upto seconds

I have to list the files of particular directory using file filter like find -name abc* something and if multiple file exist I also want time of each file up to seconds. Currently we are getting time up to minutes in AIX is there any way I can get file last modification time up to seconds. (4 Replies)
Discussion started by: Nitesh sahu
4 Replies

2. Red Hat

How to check that a particular value is epoch seconds?

how to verify that the following is epoch time. that is if i have given some random value like 34600 , how can i know it is epoch seconds (5 Replies)
Discussion started by: ramsavi
5 Replies

3. Programming

How to search a file based on a time stamp backwards 10 seconds

Hi all, I'm after some help with this small issue which i'm struggling to work out a fix for. I have a file that contains records that all have a time stamp for each individual record, i need to search the file for a specific time stamp and then search back 10 seconds to see if the number... (2 Replies)
Discussion started by: sp3arsy
2 Replies

4. UNIX for Advanced & Expert Users

How to get access time of a file upto the precision of seconds?

Hi , How can I get the last access time of a file upto the precesion of seconds in Unix. I cannot use stat as this is not supported. (10 Replies)
Discussion started by: kanus
10 Replies

5. Shell Programming and Scripting

File creation time in seconds

Hi All, Cany any one help me in solving this.. Problem statement: I have a requirement to find the time from which there are no files created in a given directory. For this I am assuming that I need to get the file creation time in seconds, then the current time in seconds using `date +%s`.... (7 Replies)
Discussion started by: chary
7 Replies

6. Shell Programming and Scripting

shell script that will automatically check if specifed user is log in or not, in 30 seconds

guys I need emergency help with below shell script assignment..am new to shell script Write a Shell script to automatically check that a specified user is logged in to the computer. The program should allow the person running the script to specify the name of the user to be checked, the... (2 Replies)
Discussion started by: gurmad
2 Replies

7. Shell Programming and Scripting

Take action only if a file is X hours (or seconds) old

shell: #!/bin/ash I searched and found a few relevant posts (here and here - both by porter, on the same day (?)) however both are just a do while loop, I need to check a file date and compare it to the current time. I would like it to say if file 'test' is more than 12 hours old than "right... (3 Replies)
Discussion started by: phdeez
3 Replies

8. Shell Programming and Scripting

Command to get File Timestamp including seconds [Aix 5.3]

Is there a command (like ls -l) to get the file time stamp including seconds? The ls -l gives only the HH:MM, No SS I don't have a C compiler to call stat() I don't a command like stat too. Please help. (8 Replies)
Discussion started by: firdousamir
8 Replies

9. Shell Programming and Scripting

Help with script, trying to get tcpdump and rotate the file every 300 seconds

Greetings, I just started using scripting languages, im trying to get a tcpdump in a file, change the file name every 5mins ... this is what i have but its not working ... any suggestions? #!/bin/bash # timeout.sh #timestamp format TIMESTAMP=`date -u "+%Y%m%dT%H%M%S"` #tdump =`tcpdump... (3 Replies)
Discussion started by: livewire
3 Replies

10. UNIX for Advanced & Expert Users

file creation date including seconds

Hi, Is anybody can help me to get the file creation date with seconds? -rw-r--r-- 1 opsc system 422550845 Aug 22 15:41 StatData.20020821 Thanks in advance Krishna (7 Replies)
Discussion started by: krishna
7 Replies
Login or Register to Ask a Question