You can capture the DEBUGsignal in the shell using a custom function.
runcmd() { if (( n==5 )); then n=0; pwd; else ((n++)); fi; }
trap 'runcmd' DEBUG
Change pwdto your custom command or script.
trap 'handler' DEBUG handler , runcmd, .
: @kojro: :
runcmd() { (( n++ % 5 )) || pwd; }