Logon script - Unix

This is a discussion on Logon script - Unix ; I am writing a logon script. Here are the things I did want to make. Connect to myself with username and pwd then connect to a differnt account on the same machine using "su". I can put this commands in ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Logon script

  1. Logon script

    I am writing a logon script.
    Here are the things I did want to make.
    Connect to myself with username and pwd
    then connect to a differnt account on the same machine using "su".


    I can put this commands in teh automated logon screen ,but I want to
    run a logon script after disabling automated logon.
    If so ,my questions...
    1.command to connect to my machine first with username and pwd to pass
    in a script.
    2.command to connect to a different user on the same machine with
    username and pwd to pass in a script using su.
    3.Where shoudl I place this script and I want to execute it everytime I
    start a new session.
    Here is the script....
    This script will connect me to diferent user but it asks me the
    password after I get connected.How should I pass the pwd also in the
    script/.
    I want to make this a automated one .
    Pls guide.

    #!/bin/ksh
    WHO=`who am i | awk '{print $1}'`
    print ${WHO}
    echo "Do you want to get connected to DIFFERENT USER? (Y/N)"
    read yorn
    if [ "${yorn}" = "Y" -o "${yorn}" = "y" ]
    then
    print ${yorn}
    su - DIFFERENT_USER
    else
    echo "You are in the directory "
    pwd
    fi


  2. Re: Logon script

    thanks Bill.
    PASSWORD="hilly"
    To pass the password value in the script I did it with su -
    user/${PASSWORD}
    This does not work.
    Can you find where I am going wrong?
    I do not want the system to ask me the password and thats why I am
    passing in the script.
    I am running a korn shell.

    Bill Marcum wrote:
    > On 25 Oct 2006 06:45:21 -0700, nicetom786@yahoo.com
    > wrote:
    > > I am writing a logon script.
    > > Here are the things I did want to make.
    > > Connect to myself with username and pwd
    > > then connect to a differnt account on the same machine using "su".
    > >
    > >
    > > I can put this commands in teh automated logon screen ,but I want to
    > > run a logon script after disabling automated logon.
    > > If so ,my questions...
    > > 1.command to connect to my machine first with username and pwd to pass
    > > in a script.

    > ssh username@mymachine
    > Set up keys so you don't need a password.
    >
    > > 2.command to connect to a different user on the same machine with
    > > username and pwd to pass in a script using su.

    > You can use expect with su, or ssh user@localhost, or use sudo with
    > NOPASSWD for the specific commands that you will execute as the other
    > user.
    >
    > > 3.Where shoudl I place this script and I want to execute it everytime I
    > > start a new session.

    > ~/.profile
    >
    > > Here is the script....
    > > This script will connect me to diferent user but it asks me the
    > > password after I get connected.How should I pass the pwd also in the
    > > script/.

    > man expect
    > man sudo
    >
    > > I want to make this a automated one .
    > > Pls guide.
    > >
    > > #!/bin/ksh
    > > WHO=`who am i | awk '{print $1}'`
    > > print ${WHO}
    > > echo "Do you want to get connected to DIFFERENT USER? (Y/N)"
    > > read yorn
    > > if [ "${yorn}" = "Y" -o "${yorn}" = "y" ]
    > > then
    > > print ${yorn}
    > > su - DIFFERENT_USER
    > > else
    > > echo "You are in the directory "
    > > pwd
    > > fi
    > >

    >
    >
    > --
    > The avoidance of taxes is the only intellectual pursuit that carries any
    > reward.
    > -- John Maynard Keynes



  3. Re: Logon script

    I kept this code in the shell scrip. but yet is asks me the password.
    How shoudl I restrict the script to ask for password as I am passing it
    hardcoded .

    su - user1
    expect "Password: "
    send "xyz"
    nicetom786@yahoo.com wrote:
    > thanks Bill.
    > PASSWORD="hilly"
    > To pass the password value in the script I did it with su -
    > user/${PASSWORD}
    > This does not work.
    > Can you find where I am going wrong?
    > I do not want the system to ask me the password and thats why I am
    > passing in the script.
    > I am running a korn shell.
    >
    > Bill Marcum wrote:
    > > On 25 Oct 2006 06:45:21 -0700, nicetom786@yahoo.com
    > > wrote:
    > > > I am writing a logon script.
    > > > Here are the things I did want to make.
    > > > Connect to myself with username and pwd
    > > > then connect to a differnt account on the same machine using "su".
    > > >
    > > >
    > > > I can put this commands in teh automated logon screen ,but I want to
    > > > run a logon script after disabling automated logon.
    > > > If so ,my questions...
    > > > 1.command to connect to my machine first with username and pwd to pass
    > > > in a script.

    > > ssh username@mymachine
    > > Set up keys so you don't need a password.
    > >
    > > > 2.command to connect to a different user on the same machine with
    > > > username and pwd to pass in a script using su.

    > > You can use expect with su, or ssh user@localhost, or use sudo with
    > > NOPASSWD for the specific commands that you will execute as the other
    > > user.
    > >
    > > > 3.Where shoudl I place this script and I want to execute it everytime I
    > > > start a new session.

    > > ~/.profile
    > >
    > > > Here is the script....
    > > > This script will connect me to diferent user but it asks me the
    > > > password after I get connected.How should I pass the pwd also in the
    > > > script/.

    > > man expect
    > > man sudo
    > >
    > > > I want to make this a automated one .
    > > > Pls guide.
    > > >
    > > > #!/bin/ksh
    > > > WHO=`who am i | awk '{print $1}'`
    > > > print ${WHO}
    > > > echo "Do you want to get connected to DIFFERENT USER? (Y/N)"
    > > > read yorn
    > > > if [ "${yorn}" = "Y" -o "${yorn}" = "y" ]
    > > > then
    > > > print ${yorn}
    > > > su - DIFFERENT_USER
    > > > else
    > > > echo "You are in the directory "
    > > > pwd
    > > > fi
    > > >

    > >
    > >
    > > --
    > > The avoidance of taxes is the only intellectual pursuit that carries any
    > > reward.
    > > -- John Maynard Keynes



  4. Re: Logon script

    I did use expect and it prompts me for the password.
    This should work right?

    su - user1
    expect "Password: "
    send "xyz"


    Bill Marcum wrote:
    > On 25 Oct 2006 09:36:29 -0700, nicetom786@yahoo.com
    > wrote:
    > > thanks Bill.
    > > PASSWORD="hilly"
    > > To pass the password value in the script I did it with su -
    > > user/${PASSWORD}
    > > This does not work.
    > > Can you find where I am going wrong?

    >
    > su doesn't work that way. It reads the password from /dev/tty, not from
    > the command line or standard input. You can either (a) execute su as
    > root, (b) use expect, (c) use sudo, or (d) ssh user@localhost, with your
    > public key in the other user's .ssh/authorized_keys .
    >
    >
    >
    > --
    > Parts that positively cannot be assembled in improper order will be.



  5. Re: Logon script

    Can some one tell me where I am going in automating the process of
    connecting to different user.

    #!/bin/ksh
    set -o emacs
    who am i
    WHO=`who am i | awk '{print $1}'`
    print ${WHO}
    echo "Do you want to get connected to USER1? (Y/N)"
    read yorn
    if [ "${yorn}" = "Y" -o "${yorn}" = "y" ]
    then
    print ${yorn}
    send "su - user1\r"
    expect "password:"
    send "xxxxx\r"

    else
    echo "You are in the directory "
    pwd
    fi
    nicetom786@yahoo.com wrote:
    > I did use expect and it prompts me for the password.
    > This should work right?
    >
    > su - user1
    > expect "Password: "
    > send "xyz"
    >
    >
    > Bill Marcum wrote:
    > > On 25 Oct 2006 09:36:29 -0700, nicetom786@yahoo.com
    > > wrote:
    > > > thanks Bill.
    > > > PASSWORD="hilly"
    > > > To pass the password value in the script I did it with su -
    > > > user/${PASSWORD}
    > > > This does not work.
    > > > Can you find where I am going wrong?

    > >
    > > su doesn't work that way. It reads the password from /dev/tty, not from
    > > the command line or standard input. You can either (a) execute su as
    > > root, (b) use expect, (c) use sudo, or (d) ssh user@localhost, with your
    > > public key in the other user's .ssh/authorized_keys .
    > >
    > >
    > >
    > > --
    > > Parts that positively cannot be assembled in improper order will be.



  6. Re: Logon script

    Thanks Bill for your response.
    I am new to unix so learning bit by bit.
    I get this error after I changed to spawn and then send and expect.
    /u01/users/logon_script.ksh[17]: expect: not found
    /u01/users/logon_script.ksh[18]: send: not found
    Bill Marcum wrote:
    > On 25 Oct 2006 10:35:58 -0700, nicetom786@yahoo.com
    > wrote:
    > > I did use expect and it prompts me for the password.
    > > This should work right?
    > >
    > > su - user1
    > > expect "Password: "
    > > send "xyz"
    > >

    > expect "string" and send "string" are expect commands, not shell
    > commands, and you would have them executed after su returns. You can
    > write a script like this:
    >
    > #!/usr/bin/expect -f
    > spawn su - user1
    > expect "Password:"
    > send "xyz"
    > interact
    >
    >
    > --
    > BOFH excuse #348:
    > We're on Token Ring, and it looks like the token got loose.



+ Reply to Thread