Polling file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Polling file
# 8  
Old 03-11-2017
Quote:
Originally Posted by mohan705
Hi ,
Below code is working fine,exit from loop if not matching .I need to be loop forever untill match both files count .Any help would be appereciated

Code:
summary=`cat ${BASE_PATH}/${FILENAME|wc -l`
check=`ls -l PASSIVELBS_xxx_*|wc -l`
while [ $summary != $check ];do 
echo "Summary files are $summary"
echo "Checksum files are $check"
echo "Files are not matching with checksum"
exit 1

Give us a break! The above code cannot possibly be "working fine".
  1. ${FILENAME is a syntax error. (Where is the closing }?)
  2. BASE_PATH is not defined!
  3. FILENAME is not defined!
  4. while [ $summary != $check ];do has no matching done! (Another syntax error.)
# 9  
Old 03-12-2017
Sorry for not giving in details ,
Code:
BASE_PATH=/home/tmp
FILENAME=summary.txt==>3 files 
These are exist in current location and wait for 3rd file to arrive  

PASSIVELBS_xxx_1
PASSIVELBS_xxx_2

summary=`cat ${BASE_PATH}/${FILENAME}|wc -l`
check=`ls -l PASSIVELBS_xxx_*|wc -l`
while [ $summary != $check ];do 
echo "Summary files are $summary"
echo "Checksum files are $check"
echo "Files are not matching with checksum"
exit 1

# 10  
Old 03-12-2017
On top of what Don Cragun already said, even your new "detailed" code suffers from
- no closing done
- entering an infinite loop as the comparison will never change

Without decent answers to my questions in post#6, assuming
- one of the possible scenarios
- a recent bash
- file count will change and not the summary.txt file
- file count exceeding summary line count is unacceptable or will never occur

, this might work for you:
Code:
SUM=$(wc -l < summary.txt)
while (( SUM - 2 - $(ls PASSIVE* | wc -w) ))
  do    echo NO
        sleep 1
  done

# 11  
Old 03-12-2017
Please oh please, read your code again!
You are here to obtain help and this is the second time this code won't work.
Don has already told you many faults now you have others...
Code:
BASE_PATH=/home/tmp
FILENAME=summary.txt==>3 files 
These are exist in current location and wait for 3rd file to arrive  

PASSIVELBS_xxx_1
PASSIVELBS_xxx_2

summary=`cat ${BASE_PATH}/${FILENAME}|wc -l`
check=`ls -l PASSIVELBS_xxx_*|wc -l`
while [ $summary != $check ];do 
echo "Summary files are $summary"
echo "Checksum files are $check"
echo "Files are not matching with checksum"
exit 1

Longhand, OSX 10.7.5, default bash terminal...
Code:
Last login: Sun Mar 12 10:12:11 on ttys000
AMIGA:amiga~> cd Desktop/Text
AMIGA:amiga~/Desktop/Text> chmod 755 junk.txt
AMIGA:amiga~/Desktop/Text> cat junk.txt
BASE_PATH=/home/tmp
FILENAME=summary.txt==>3 files 
These are exist in current location and wait for 3rd file to arrive  

PASSIVELBS_xxx_1
PASSIVELBS_xxx_2

summary=`cat ${BASE_PATH}/${FILENAME}|wc -l`
check=`ls -l PASSIVELBS_xxx_*|wc -l`
while [ $summary != $check ];do 
echo "Summary files are $summary"
echo "Checksum files are $check"
echo "Files are not matching with checksum"
exit 1
AMIGA:amiga~/Desktop/Text> 
AMIGA:amiga~/Desktop/Text> 
AMIGA:amiga~/Desktop/Text> ./junk.txt
./junk.txt: line 2: files: command not found
./junk.txt: line 3: These: command not found
./junk.txt: line 5: PASSIVELBS_xxx_1: command not found
./junk.txt: line 6: PASSIVELBS_xxx_2: command not found
cat: /home/tmp/: No such file or directory
ls: PASSIVELBS_xxx_*: No such file or directory
./junk.txt: line 15: syntax error: unexpected end of file
AMIGA:amiga~/Desktop/Text> _

As there is no line 15 then you still have an error that Don has already told you about!
Please be accurate as it helps us to help you.
# 12  
Old 03-12-2017
FWIW - Is there some logical reason why you cannot directly observe the 3 files you want instead of all of this other indirect logic.

This has a timed loop that returns an error after one hour of waiting.
It also polls the files once every 10 seconds, and emails okay or failure
Code:
#!/bin/bash
# file: poll.sh
cnt=0
now=$( date +%s )   # time in epoch seconds
when=$(( $now + 86400 ))  # we will only wait 1 hour then produce an error

while [ $cnt -le 3 ]
do
     if [ $( date +%s ) -gt $when ]; then
         echo 'Timed out: failure to find files' | 
              mailx -s 'poll.sh failed'  mohan@somewhere.com
         exit 1
     fi
     cnt=`ls -1 PASSIVE_XXX_? | wc -l`   # cnt will be at least 3 in order to end loop
     sleep 10   # wait 10 seconds before trying again.
done
echo 'All files found' | mailx -s 'poll.sh okay'  mohan@somewhere.com
exit 0

usage:
Code:
/path/to/poll.sh

This is somewhat verbose but it shows exactly what you need to do. Ignoring the likelihood that the filenames (PASSIVE*) are not as you presented them.
# 13  
Old 03-13-2017
Using a recent bash's features, you can test if exactly the named files are present:

Code:
mapfile -ts2 FNS <summary.txt
while [ ${MISS:-1} -eq 1 ]
  do    MISS=0
        for I in ${!FNS[@]}
          do    [ -e ${FNS[$I]} ] || { MISS=1; sleep 1; }
          done
  done

This will create an array with the file names expected, and then loop until ALL files exist; if any one is missing, it will wait some time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Polling target on Serviceguard

Hi Guys, we are planning to enable polling target on our SG in reference to this link MC/ServiceGuard: Subnet Goes Down when one of the Cluster Node is Down - HP Customer Care (United States - English) since our server is already in production can we apply the changes with ex. "cmapplyconf... (1 Reply)
Discussion started by: batas
1 Replies

2. Shell Programming and Scripting

Polling for existence of file on remote host

I am polling a file on remote host. I have this code that works, but can't explain why it works. while user@remote.no-exist.com 'ls /user/app1/.done'` ] do echo Sleeping for 5 secs sleep 5; done This code works in the way that when the .done file exists on the remote host, the script... (1 Reply)
Discussion started by: starlatch
1 Replies

3. Programming

Db polling...

Hi! Im trying to make a program that polls a mysqlDB every 5 minutes. the poll checks a scheduletable in the dB and exicutes a function if there was a "go" in the scheduletable, and if it retrives a "no go" from the table it should just wait for another 5 minutes before re polling the DB, ... (1 Reply)
Discussion started by: karlblau
1 Replies

4. Solaris

NTP polling interval

Is it possible to change the ntp poll manually. I notice that ntp poll is changing autimatically. (1 Reply)
Discussion started by: ningy
1 Replies

5. Shell Programming and Scripting

Unix Polling agent

I plan to run a script which will run in background and at predefined times send mails to user . I dont have acees to autosys/ Cron / at jobs My loop works like this while (true) do getx_time=`date +%H%M` if ; then script1.sh mail_sent_flag=1 elif ; then script2.sh... (1 Reply)
Discussion started by: ultimatix
1 Replies

6. Shell Programming and Scripting

Polling continously for presence of a file

Hi, My os is sun solaris 5.10 and Korn shell scripting. I have a file name like CCNA_EARLY_SWP.w062309 where 062309 is date in mmddyy .This is the value date of the file.(will I need to check continously from 5.00 - 7.00 am daily for this file . If the file has not come at 5 am or 7am... (4 Replies)
Discussion started by: manoj39
4 Replies

7. UNIX for Advanced & Expert Users

How to avoid polling???

Hi all, I have a directory where some process is keeping incremental/new log files. I need to code a program which will periodically poll this directory and if it founds a new file arrived then copy that new file to some other specific directory. We are OK with this polling approach. I just... (3 Replies)
Discussion started by: zing_foru
3 Replies

8. UNIX for Advanced & Expert Users

Polling an FTP site for a file

Hi, I'm after a bit of advice for the best way to collect files from an ftp server via a unix process. The main issue here is the frequency, the job needs to check for files every minute or so between 8am and 8pm and pull them down to the box if there is anything there. Originally the... (6 Replies)
Discussion started by: Peejay
6 Replies

9. Programming

How to implement polling for a function using timer in C?

Hi, Can you please help me in implementing a timer based polling for function in C? ie. the function should be called in say 30secs(when 30secs has lapsed). Thanks (7 Replies)
Discussion started by: naan
7 Replies

10. Programming

Help - Polling Script

How do I write a shell script to perform polling just like what happens with Microsoft mail. i.e display an alert box. (1 Reply)
Discussion started by: brianmu
1 Replies
Login or Register to Ask a Question