LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-26-2009, 10:01 AM   #1
Techno Guy
Member
 
Registered: Dec 2008
Posts: 62

Rep: Reputation: 15
Loop or check SQlite3 database continuously, when query found run script for first 3


I have a SQlite database gets populated when ever someone adds a filename and dir to it, then I want the script to read the newest 3 entries (done with the "LIMIT 3") then I want this script to take those 3 entries and start the "script1.sh" for each of them, then once the script1 has finished one of the 3, I want it to look back into the SQlite database and check if there are any new entires and repeat. (so kinda like a queue)
NOTE, at the end of script1.sh there is a command that will delete it's entry from the SQlite DB.

So basically I want the script to check the SQlite DB each time one script1.sh script finishes.

So far I have:
Code:
#!/bin/bash

sqlite3 /database.db  "SELECT * FROM main ORDER BY mKey ASC LIMIT 3" | while read file
do
	fileName=`echo "$file" | awk '{split($0,a,"|"); print a[2]}'`
	echo "$fileName"
 
        #Run script
        ./script1.sh "$fileName" "$file"
 

done
appreciate any help.
 
Old 09-27-2009, 02:23 PM   #2
chr15t0
Member
 
Registered: Jun 2002
Location: London
Distribution: Slackware
Posts: 201

Rep: Reputation: 30
why not make this process part of the script1.sh?
 
Old 09-27-2009, 07:36 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You can't mix a queue of len=1 and len=3. You won't be able to keep track of what's actually been processed.
Personally, I'd do the whole thing top to bottom in Perl, and name the column I need; never use 'SELECT *' in prod code, there's no guarantee that col names will always appear in the same order, even if they do right now.
 
Old 09-27-2009, 07:46 PM   #4
Techno Guy
Member
 
Registered: Dec 2008
Posts: 62

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
You can't mix a queue of len=1 and len=3. You won't be able to keep track of what's actually been processed.
Personally, I'd do the whole thing top to bottom in Perl, and name the column I need; never use 'SELECT *' in prod code, there's no guarantee that col names will always appear in the same order, even if they do right now.
Yeah true, thanks for that, i'v changed the "*" to the "fileName" field and thus I could get rid of the awk.

And i'v found a solution to my question, im just using SQlite and check the status of the file ever x seconds in a continues loop

@ chr15t0, Because .... I have my reason, just don't remember what they where right now :P
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run the /usr/sbin/in.tftpd script in the background continuously? sharu99 Linux - Newbie 8 10-31-2008 12:20 AM
Run script in a loop anjanesh Linux - General 5 03-07-2007 10:16 PM
continuously run a command? slinky2004 Linux - Newbie 2 11-04-2005 10:03 PM
ntpd won't run continuously jeffbarish Linux - Networking 3 10-04-2005 02:29 PM
Script Errors (loop, menu, etc, not found) dolvmin Linux - Software 7 08-14-2003 12:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration