Hello,
it is basic script, I'd like to write it for you.
I'm going to store $i value in external file, placed in the same directory, where script is placed.
I'll test script on my test machine and then provide you the script.
Please let me know if you have questions.
Kind regards,
Vladimir Solovyov