I love C myself...this does what you want I think. Only has 3 processes ever run. And since you're not worried about SQL errors apparently no need to use the sqlite library. A couple of changes to match your iostat output is all that's needed. I assume you know C (a rather large assumption I must admit)
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { FILE *pipe1,*pipe2; char buf[4096]; char scan[4096]; if (argc != 2) { fprintf(stderr,"Usage: %s [device]\n",argv[0]); exit(1); } //sprintf(buf,"iostat -d -w 10 %s",argv[1]); sprintf(buf,"iostat %s 2",argv[1]); pipe1=popen(buf,"r"); if (pipe1 == NULL) { perror("iostat"); exit(1); } pipe2=popen("sqlite3 test.db","w"); if (pipe2 == NULL) { perror("sqlite3"); exit(1); } sprintf(scan,"%s %%lf %%lf %%lf",argv[1]); while(fgets(buf,sizeof(buf),pipe1)) { char sql[4096]; double d1, d2, d3; int n=sscanf(buf,scan,&d1,&d2,&d3); if (n == 3) { printf("%s %f %f %f\n",argv[1],d1,d2,d3); sprintf(sql,"insert into io values(datetime(\'now\',\'localtime\'),%f,%f,%f",d1,d2,d3); //fprintf(pipe2,"%s\n",sql); puts(sql); } } pclose(pipe1); return 0; } Michael D. Black Senior Scientist NG Information Systems Advanced Analytics Directorate From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of Patrick Proniewski [pat...@patpro.net] Sent: Tuesday, September 27, 2011 6:10 AM To: General Discussion of SQLite Database Subject: EXT :Re: [sqlite] feed "endless" data into sqlite, thru a shell script On 27 sept. 2011, at 08:31, Baptiste Daroussin wrote: > You don't need awk :) > > iostat -d -w 10 disk0 | while read a b c; do case $a in *[a-zA-Z]*) > continue ;; *) sqlite3 iostat.db "INSERT INTO io > VALUES(datetime('now', 'localtime'), \"$a\", \"$b\", \"$c\");" ;; > esac; done Ok, this forks less, but still, you can't get rid of the loop ;) (I love awk) thanks, patpro _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users