Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2003
    Posts
    13

    Unanswered: doing a login in from a script

    Hey,

    I am trying to create a script that will will log into a process and then exit.

    The command is hastatus and I am trying to supply a username and password. How do I simulate a carriage-return and a ctrl-c to then exit the process. I need to then check if certain groups are offline.

    This is what I have (that doesn't work). Any help would be greatly appreciated:

    #!/usr/bin/ksh
    VAR="netrac\n"
    VAR1="qwer90\n"
    printf $VAR
    printf $VAR1
    /opt/VRTSvcs/bin/hastatus <<!
    printf $VAR
    printf $VAR1
    ! >>

  2. #2
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    in vi you can use CTRL-v to insert ESC-Sequenz.

    Example : vi INSERT-Mode type CTRL-v and then ENTER. You get "^R".
    This is an CR in shell enviromente. Also do with CTRL-c.
    Type CTRL-v and then CTRL-c. You get a "^C" in vi.
    CTRL-v only works for one character.

    Peter F.
    Last edited by fla5do; 11-10-03 at 17:37.
    Greetings from germany
    Peter F.

  3. #3
    Join Date
    Sep 2003
    Posts
    13
    Thanks,

    I still can't get a carriage return after the "VCS Login:" It runs the userid and password together and I need to send the userid, then CR, then th password at the password prompt, and enter. Then after the status has been shown, I need to ctrl-c. Unfortunately, I can't get the CR (^M) or the Ctrl-C (^C) to work.

    Am I missing something?

    This is what I have:

    #!/bin/ksh
    VAR=userid
    VAR1=passwordval
    /opt/VRTSvcs/bin/hastatus <<!
    print $VAR^M
    print $VAR1^M
    sleep 15
    ^C
    !>>

    So, I'm trying to run the hastatus command, pass it the userid, CR, pass it the password, hit return, then ctrl-c out. When I run it I get this:

    attempting to connect....
    VCS Login:Password:

  4. #4
    Join Date
    Dec 2002
    Posts
    104
    Originally posted by jwdtacos
    Thanks,

    I still can't get a carriage return after the "VCS Login:" It runs the userid and password together and I need to send the userid, then CR, then th password at the password prompt, and enter. Then after the status has been shown, I need to ctrl-c. Unfortunately, I can't get the CR (^M) or the Ctrl-C (^C) to work.

    Am I missing something?

    This is what I have:

    #!/bin/ksh
    VAR=userid
    VAR1=passwordval
    /opt/VRTSvcs/bin/hastatus <<!
    print $VAR^M
    print $VAR1^M
    sleep 15
    ^C
    !>>

    So, I'm trying to run the hastatus command, pass it the userid, CR, pass it the password, hit return, then ctrl-c out. When I run it I get this:

    attempting to connect....
    VCS Login:Password:
    hi!

    Instead of print try using echo

    For example:
    #!/bin/ksh
    VAR=userid
    VAR1=passwordval
    /opt/VRTSvcs/bin/hastatus <<!
    echo $VAR
    echo $VAR1
    sleep 15


    hope this will work

    cheers,
    Pooja

  5. #5
    Join Date
    Sep 2003
    Posts
    13
    Hi, thanks.

    I've tried that and just about everything else.

    It seems like a buffer is getting flushed and it is not taking CRs or seeing the password value.

    At this point I am left to trying to use the freely available autoexpect script in the expect module to try and write a non-interactive login script.

    If anybody has any experience going this route, please feel free to advise me.

    Thanks,
    JD

  6. #6
    Join Date
    Sep 2003
    Posts
    13
    Just as an FYI for everyone else, if you run into this problem with a command that is interactive or needs a username/password and shell scripting isn't doing the job, the freely available autoexpect script that comes with expect works beautifully.

    You run it with the the interactive command as an argument and then interact with the command the normal way. Autoexpect will then create a script that will automatically do what you did.

    Very nice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •