Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm trying to monitor the progress of a sqlite3 command importing a large .sql file into a database using zenity --progress.

I've tried the following which will import the file, however progress is not shown:

sqlite3 DATABASE < import_file.sql | zenity --progress --percentage=0 --auto-close

I know I need to provide zenity a numeric source for the progress, but don't really know how to obtain the number.

Can anyone help me?

share|improve this question
add comment

1 Answer

The sqlite3 tool does not output such numbers.

You would have to write some script that feeds the lines of the import file into sqlite3, and at the same time feeds the percentage numbers into zenity. Try something like this:

#!/bin/bash
maxlines=$(wc -l < import_file.sql)
exec 3> >(zenity --progress --auto-close)
counter=0
while IFS= read -r line; do
    echo "$line"
    counter=$(($counter+1))
    echo $(($counter * 100 / $maxlines)) >&3
done < import_file.sql

Call it with thescript | sqlite3 dbfile.

share|improve this answer
    
I tried this out and the zenity bar seems to start about 4/5 of the way complete. I tried initializing the zenity --progress bar at 0, but that didn't help either. –  WRSaber Oct 1 '12 at 21:31
    
It's likely that the first lines in your file are executed faster. –  CL. Oct 2 '12 at 7:30
    
I don't think so. The entire file is one big mass of insert statements. Nothing is different in the beginning. Also, the zenity progress bar is at 100 percent after about 3-5 seconds, but the sqlite3 statement doesn't finish until a long time after. Strange. –  WRSaber Oct 2 '12 at 13:07
    
Output the percentages to the console (>&2 instead of >&3) to check whether they are correct. –  CL. Oct 2 '12 at 13:34
    
The numbers look correct. It does the count from 0 to 100. However, it's like the console won't kill the process when it's complete (even with --auto-kill). –  WRSaber Oct 2 '12 at 15:35
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.