It should not be a problem, but it is. Even if you do connect from inside the LAN, somebody else can do that as well -- nothing is bullet-proof
I think it's rather easy storing the password to a variable (for example) and giving it when asked; a simple loop can do the rest. If I'm not completely mistaken, this site linuxcommand.org has the steps you're asking (if not directly, then indirectly). In addition I've found, using google, a program that you can use to "record" a session -- shortly said you launch the program, it starts "listening", you log on to the machines and do whatever you're supposed to, then log off and stop recording. The idea is like creating a "macro" (though I'm not sure if one could call it a macro). After this, or rather after you've reviewed the "code", the "recorded" thing should be able to do all that by itself, answering to password prompts etc. The bad part is, I can't remember for the life of me what the program was called -- but it's not anything new, it's rather grown-up already.
I'm sure Google finds you more. And remember to check out linuxcommand.org!