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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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:

maxlines=$(wc -l < import_file.sql)
exec 3> >(zenity --progress --auto-close)
while IFS= read -r line; do
    echo "$line"
    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

Your Answer


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.