Operating System - HP-UX
1833758 Members
2575 Online
110063 Solutions
New Discussion

user login using shell script

 
rajeesh k menon
Frequent Advisor

user login using shell script

hi all

how can i login using shell svript?

I know i am able to do su - username

but how can I issue the password

suggestions !!!!

regards

rajeesh
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: user login using shell script

Hi:

If you wish to define a user account that when the user logins in, a particular script or executable file is always run, then you can define the executable as the shell program in '/etc/passwd'. That is, instead of the normal '/usr/bin/sh' (for instance), substitute your program.

If you need to run a particular program and pass some static parameters, place an 'exec' statement at the end of the user's profile, instead. For example:

# exec mything -f myfile

...when the profile is read by login, 'mything' wili become the user's running environment. When 'mything' exits, the user will be logged off. This applies similarly when declaring '/usr/local/bin/mything' as the program name in an account in '/etc/passwd'.

Regards!

...JRF...

RAC_1
Honored Contributor

Re: user login using shell script

You have few options. The best one would be using ssh. (set it to passwordless authentication)

Then you can use expect tool for it. You can get it on any of the HP porting centers. (http://hpux.connect.org.uk)

You may be able to use following code. Check it.

(sleep 2;echo "user_name";sleep 1;echo "user_password";sleep 2;echo "ls";echo "exit 0") | telnet â hostâ
{sleep 2;echo "user_name";sleep 1;echo "user_password";sleep 2;echo "ls";echo "exit 0" ; } | telnet "host"
There is no substitute to HARDWORK
doug hosking
Esteemed Contributor

Re: user login using shell script

The (free) 'expect' tool is definitely something worth looking into. There is lots of information at http://expect.nist.gov/ . A sample script that uses expect is at http://expect.nist.gov/example/rlogin-cwd .

O'Reilly has a book about programming in Expect:

http://www.oreilly.com/catalog/expect/

spex
Honored Contributor

Re: user login using shell script

Hi rajeesh,

As root, you can 'su' to anyone's account without supplying a password.

PCS
rajeesh k menon
Frequent Advisor

Re: user login using shell script

thaks you