Loop or check SQlite3 database continuously, when query found run script for first 3
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.