newbie: "myexpect.c" or "use fscanf?"

newbie: "myexpect.c" or "use fscanf?"

Post by gaius.petroni » Sat, 29 Dec 2001 13:03:37



newbie says it all.

in lieu of having an ssh agent running in memory with a "" password,
i'd like to write a routine that can process the Unix command line:

# for s in `cat ${list of servers}` do
     scp -p $i:${archive_dir}/* local_archive_dir/ ;done

first off, is this the wrong way to go about this in this first place?

if this is reasonable, here is my first step:

/*      myexpect.c
 *
 *      Purpose: automate interactive sessions where user input is required
 *      Details: In the case of a session where a password is required
multiple
 *               times, store the password in a variable and supply to each
 *               system call
 */

#include <stdio.h>
/* other libraries are undoubtedly required here */

main(argc, arv)
        int arg;
        char *arv[]; {
                char pfile[]="/root/pfile";
                char cmd[]=&argv[0];
                /* declare a variable for the interactive prompt of the Unix command
*/
                /* store the arguments to the program as a Unix command
                 * and its valid arguments */
                /* request the password and store as an encrupted file */
                /* for each interactive request/prompt of the Unix command, write
the
                 * contents of the password to stdout as many times as the Unix
command
                 * loops */
        }

This is my algorithm.
So i know i must send the Unix commandline to stdin (to the system)
and then capture each request the command makes for stdin and send the
password to stdout.

is there a better way?
i do not want to use ssh key agent as a blank password,
but i *do* want to use ssh (scp) for moving my dumps across the
network to another machine.

risks? improvements? ideas? suggestions? comments?
and TIA

 
 
 

newbie: "myexpect.c" or "use fscanf?"

Post by eric » Tue, 01 Jan 2002 01:59:21



> newbie says it all.

> in lieu of having an ssh agent running in memory with a "" password,
> i'd like to write a routine that can process the Unix command line:

> # for s in `cat ${list of servers}` do
>      scp -p $i:${archive_dir}/* local_archive_dir/ ;done

> first off, is this the wrong way to go about this in this first place?

I'd use something like expect or the perl expect module.  It's designed
to be a scripting language that does interaction automatically.  I
believe that it even has a record function so you can walk through one
and get a skeleton example.

Eric

 
 
 

newbie: "myexpect.c" or "use fscanf?"

Post by gaius.petroni » Tue, 01 Jan 2002 10:21:27





> > in lieu of having an ssh agent running in memory with a "" password,
> > i'd like to write a routine that can process the Unix command line:

> I'd use something like expect or the perl expect module.  It's designed
> to be a scripting language that does interaction automatically.  I
> believe that it even has a record function so you can walk through one
> and get a skeleton example.

this needs to be in C , compiled and the binary placed on the machine
 
 
 

newbie: "myexpect.c" or "use fscanf?"

Post by gaius.petroni » Sat, 05 Jan 2002 13:53:03


Can anyone provide any comments on my below algorithm?
Or perhaps point me to examples of interactive with encryption?

Basically what i want to accomplish is sending ssh the password from
an encrypted file and then of course wiping the file when it is done.

Quote:> newbie says it all.

> in lieu of having an ssh agent running in memory with a "" password,
> i'd like to write a routine that can process the Unix command line:

> # for s in `cat ${list of servers}` do
>      scp -p $i:${archive_dir}/* local_archive_dir/ ;done

> first off, is this the wrong way to go about this in this first place?

> if this is reasonable, here is my first step:

> /* myexpect.c
>  *
>  * Purpose: automate interactive sessions where user input is required
>  * Details: In the case of a session where a password is required
> multiple
>  *          times, store the password in a variable and supply to each
>  *          system call
>  */

> #include <stdio.h>
> /* other libraries are undoubtedly required here */

> main(argc, arv)
>    int arg;
>    char *arv[]; {
>            char pfile[]="/root/pfile";
>            char cmd[]=&argv[0];
>            /* declare a variable for the interactive prompt of the Unix command
> */
>            /* store the arguments to the program as a Unix command
>             * and its valid arguments */
>            /* request the password and store as an encrupted file */
>            /* for each interactive request/prompt of the Unix command, write
> the
>             * contents of the password to stdout as many times as the Unix
> command
>             * loops */
>    }

> This is my algorithm.
> So i know i must send the Unix commandline to stdin (to the system)
> and then capture each request the command makes for stdin and send the
> password to stdout.

> is there a better way?
> i do not want to use ssh key agent as a blank password,
> but i *do* want to use ssh (scp) for moving my dumps across the
> network to another machine.

> risks? improvements? ideas? suggestions? comments?
> and TIA