Can anyone point where I am going wrong ??? - Unix

This is a discussion on Can anyone point where I am going wrong ??? - Unix ; I Placed korn shell script and placed in the .profile. This shell is supposed to ask me to connnect to a different user ,If yes input password then I will get connected ,if not I will be in my account. ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Can anyone point where I am going wrong ???

  1. Can anyone point where I am going wrong ???

    I Placed korn shell script and placed in the .profile.
    This shell is supposed to ask me to connnect to a different user ,If
    yes input password then I will get connected ,if not I will be in my
    account.
    But the script skips without asking me Yes /No,thereby keeping it
    connected to my account.

    This script runs fine when I execute it outside .profile

    There are 3 issues wrt this script.

    1.It does not ask me whether to get connected or not when I place in
    ..profile?
    2.I want to pass the password for that different user .I tried using
    "expect" and "send".But the ksh shell says
    logon_script.ksh[13]: expect: not found
    logon_script.ksh[14]: send: not found
    3.This script runs fine when I execute it outside .profile

    Can anyone try where I am going wrong.

    Code is here
    #!/usr/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}
    echo -en "\033]2;USER1\007"
    su - user1
    set -o emacs
    cd tws
    else
    echo "You are in the directory "
    pwd
    echo -en "\033]2;My Window\007"
    fi


  2. Re: Can anyone point where I am going wrong ???

    If the script works fine when running in a normal ksh, then its gonna
    be something like a PATH issue .. so make sure you set your PATH at the
    top of your script or usr full paths to your commands.

    HTH
    Mark Taylor


  3. Re: Can anyone point where I am going wrong ???


    nicetom786@yahoo.com wrote a long message, and Steve responded...

    I was unable to pass the su command the password for the USER1 user,
    but it did not skip the if statement on me when I used the .profile
    shown below. Further down is my sample output. I suspect that you will
    need to use an "expect" script instead to send the password as a
    parameter.

    SAMPLE SCRIPT
    =============
    #!/usr/bin/ksh
    WHO=$(who am i | awk '{print $1}')
    echo "\nYou are currently connected as user: ${WHO} "
    echo "Do you want to get connected to USER1? (Y/N)"
    read YORN
    if test "${YORN}" = "Y" -o "${YORN}" = "y"
    then
    echo "Connecting to USER1..."
    su - user1
    else
    echo "Connecting to $WHO..."
    echo "You are in directory: $(pwd)"
    fi

    SAMPLE OUTPUT
    =============
    pts/1 login: steven
    steven's Password:
    ************************************************** *****************************
    * Welcome to KAOS AIX Version 5.1.0, 32-bit

    ************************************************** *****************************
    Last unsuccessful login: Fri Sep 29 08:45:37 EDT 2006 on /dev/pts/0
    Last login: Thu Oct 26 15:07:40 EDT 2006 on /dev/pts/1

    You are currently connected as user: steven
    Do you want to get connected to USER1? (Y/N)
    y
    Connecting to USER1...
    user1's Password:
    Welcome to USER1!
    $


  4. Re: Can anyone point where I am going wrong ???

    Thanks Steven.
    The code worked after I removed commands at the automated login script
    screen.
    For the second part to pass password in the script ,I tried using
    spawn,expect ,send but all the above ar not reconised in the korn
    shell.
    Also I am able to man(reference) any of these .
    Can you give me some idea.

    steven_nospam at Yahoo! Canada wrote:
    > nicetom786@yahoo.com wrote a long message, and Steve responded...
    >
    > I was unable to pass the su command the password for the USER1 user,
    > but it did not skip the if statement on me when I used the .profile
    > shown below. Further down is my sample output. I suspect that you will
    > need to use an "expect" script instead to send the password as a
    > parameter.
    >
    > SAMPLE SCRIPT
    > =============
    > #!/usr/bin/ksh
    > WHO=$(who am i | awk '{print $1}')
    > echo "\nYou are currently connected as user: ${WHO} "
    > echo "Do you want to get connected to USER1? (Y/N)"
    > read YORN
    > if test "${YORN}" = "Y" -o "${YORN}" = "y"
    > then
    > echo "Connecting to USER1..."
    > su - user1
    > else
    > echo "Connecting to $WHO..."
    > echo "You are in directory: $(pwd)"
    > fi
    >
    > SAMPLE OUTPUT
    > =============
    > pts/1 login: steven
    > steven's Password:
    > ************************************************** *****************************
    > * Welcome to KAOS AIX Version 5.1.0, 32-bit
    >
    > ************************************************** *****************************
    > Last unsuccessful login: Fri Sep 29 08:45:37 EDT 2006 on /dev/pts/0
    > Last login: Thu Oct 26 15:07:40 EDT 2006 on /dev/pts/1
    >
    > You are currently connected as user: steven
    > Do you want to get connected to USER1? (Y/N)
    > y
    > Connecting to USER1...
    > user1's Password:
    > Welcome to USER1!
    > $



  5. Re: Can anyone point where I am going wrong ???

    > Thanks Steven.
    > The code worked after I removed commands at the automated login script
    > screen.
    > For the second part to pass password in the script ,I tried using
    > spawn,expect ,send but all the above ar not reconised in the korn
    > shell.
    > Also I am able to man(reference) any of these .
    > Can you give me some idea.


    have you installed "expect" ? I thought you said the script worked when
    you ran it in the shell ? so it didnt work really ?

    You can get the expect rpm from the aixtoolbox

    HTH
    Mark Taylor


  6. Re: Can anyone point where I am going wrong ???


    nicetom786@yahoo.com wrote:
    > Thanks Steven.
    > The code worked after I removed commands at the automated login script
    > screen.
    > For the second part to pass password in the script ,I tried using
    > spawn,expect ,send but all the above ar not reconised in the korn
    > shell.
    > Also I am able to man(reference) any of these .
    > Can you give me some idea.


    All I can tell you about "expect" is that it has its own coding syntax,
    much like Korn Shell or Perl. You would have to take a look at sample
    expect scripts or find more info on the net, because I have not seen
    any man pages for the expect package.

    We have an expect script we use at our help desk to log on to other
    systems so that usernames and passwords are not required to be
    remembered by or displayed to the help desk staff. I was not involved
    in the creation of the script so cannot tell you how it works or how to
    code yours properly.

    Just Google for "expect script UNIX" and you probably will get some
    examples or documentation.

    Steve


  7. Re: Can anyone point where I am going wrong ???

    On 27 Oct 2006 07:41:07 -0700, nicetom786@yahoo.com wrote:
    > Thanks Steven.
    > The code worked after I removed commands at the automated login script
    > screen.
    > For the second part to pass password in the script ,I tried using
    > spawn,expect ,send but all the above ar not reconised in the korn
    > shell.
    > Also I am able to man(reference) any of these .
    > Can you give me some idea.


    Here try this
    autoexpect

    If you do not have man page

    http://manpage.willempen.org/1/autoexpect
    for others
    http://manpage.willempen.org

    Snippet from
    $ cat /usr/share/doc/expect-5.43.0/README


    Expect may be ftp'd as mel/div826/subject/expect/expect.tar.gz from
    expect.nist.gov. (Yes, the URL is much shorter:
    http://expect.nist.gov/expect.tar.Z) Request email delivery by mailing
    to "library@cme.nist.gov". The contents of the message should be (no
    subject line) "send pub/expect/expect.tar.Z".

    Once you have retrieved the system, read the INSTALL file. The papers
    mentioned above can be retrieved separately (from the same directories
    listed above) as:

    doc/seminal.ps.Z (USENIX '90 - Intro and Implementation)
    doc/sysadm.ps.Z (LISA '90 - System Administration)
    doc/scripts.ps.Z (Comp. Systems '91 - Overview of Scripts)
    doc/regress.ps.Z (USENIX '92 - Testing)
    doc/kibitz.ps.Z (SP&E '93 - Automating Multiple
    Interactive Programs Simultaneously)
    doc/tcl-debug.ps.Z (Tcl/Tk '93 - Tcl/Tk Debugger)
    doc/expectk.ps.Z (Xhibition '94 - Using Expect with Tk)
    doc/bgpasswd.ps.Z (LISA '94 - Passwds in Background Procs)
    doc/chargraph.ps.Z (SP&E '96 - Testing and Automation
    of Character Graphic Applications)


+ Reply to Thread