This can also be achieved using wmctrl:
sudo apt-get install wmctrl
Script for wmctrl:
#!/bin/sh
while true
do wmctrl -s 0
sleep 5
wmctrl -s 1
sleep 5
wmctrl -s 2
sleep 5
wmctrl -s 3
sleep 5
done
wmctrl is a more elegant solution; it sends messages to the window manager and can do other things like move windows to a specific workspace or raise them which may also be useful to you. However, the window manager is free to ignore these messages so it is perhaps not the most portable solution.
wmctrl's -a option is the most suitable for your use: it will switch to the correct workspace and then raise the window. This avoids having to keep the windows on the correct workspaces, not minimized, and not obscured by other windows etc.