The passwd utility reads directly from a tty, so writing to it's stdin will have no effect. The Expect language has been designed with this type of interface in mind, and is commonly used to automate passwd, telnet, and other sessions that rely on waiting for and reacting to specific program output.
Expect is available at http://expect.nist.gov/. The examples it comes with include passwd automation, I believe. The Expect language is based on TCL.
There is a Perl module for Expect available from www.cpan.org if you want Expect's functionality from within a Perl script.
And for that I tried to install the expect.
I was able to run the configure file but when I was running:
make expect
It was giving following error:"Can't open include file 'tclPort.h'"
Can anybody help tell me how to solve this problem.
I have also installed ActiveTcl.
Using expect here seems to be using a sledgehammer to crack a nut. Why not simply use the unix file permissions. Get the owner of the script to add execute permissions for group or all on the script in question - see chmod.