#!/bin/sh #!/usr/local/bin/expect # you may have to change the path of expect above. # do a "which expect" in the machine you're on aand see what is the path... # here's a small expect script that does the following - # 1> logs into a machine # 2> executes a program # 3> provides inputs to the program # 4> logs out of the machine # for more information on how to write expect scripts, # read the unix manuals on expect & autoexpect (man expect) # this is just an example, u don't have to startup ur client/server etc. # in the same way. # replace username with ur login name spawn ssh username@bert.cs.pitt.edu expect -exact "username@bert.cs.pitt.edu's passwd: " # replace password with ur own passwd send -- "password\r" # replace the prompt with ur own prompt expect "bash-2.04\$ " # change to the executable directory send -- "cd test\r" expect "bash-2.04\$ " # run client send -- "client\r" # note: the executable should be compiled for the target host expect -exact "client\r *Menu*\r 1. get server list\r 2. send request\r 3. quit\r enter choice: " # enter choice 1 send -- "1\r" expect -exact "1\r *Menu*\r 1. get server list\r 2. send request\r 3. quit\r enter choice: " # enter choice 3. i.e., quit send -- "3\r" expect -exact "3\r bash-2.04\$ " send -- "exit\r" expect eof # listing of client program source code # #include # main() # { # while(1) # { # int choice; # printf("*Menu*\n"); # printf("1. get server list\n"); # printf("2. send request\n"); # printf("3. quit\n"); # printf("enter choice: "); # scanf("%d",&choice); # switch(choice) # { # case 1: break; # case 2: break; # case 3: exit(0); # default: printf("invalid choice\n"); # } # } # }