This sounds a bit difficult using shell script. Try enabling ssh for the required users, that should be a cake walk. If you still want to do it with script, probably you should try expect
I dont know exeactly what do you want but i try to make some simple script.
first of all you have to root permission.
if you change home directory other user then you need write permission in home directory else we get error like in below (permission error)
after you must run visudo and add pkbond to wheel group.
because of usermod is neccessary us and this is super command.
[pkbond@rhnserver ~]$ ./justdoit
Before running script
/home/oper/pkbond
uid=514(pkbond) gid=514(oper)
mkdir: cannot create directory `/home/oper/ab01': Permission denied
Only root can do that.
ab01 processes are OK!!
After running script
/home/oper/ab01
uid=514(ab01) gid=514(oper)
ab02 is not logged or is not parameter list!!
I really wish people would stop suggesting expect as the duct-tape universal solution to interactive login issues. They're often not doing you any favors and inviting the creation of moon-sized security holes. These utilities are designed to prevent you from using stored plaintext passwords for a reason -- it's a really bad idea.
Do what you need to do as root instead, or perhaps with sudo configured to let you and only you do this and only this one particular thing as root, in one particular way. Things shouldn't prompt you for user passwords when you're root, which prevents the need for an insecure file holding the passwords for every user on your system, in plaintext. Sheesh!