tame1 has asked for the wisdom of the Perl Monks concerning the following question:

I haven't done any real perl work for 3 years, so I am very rusty.

I am trying to create a boot CD which will turn a home PC into a secure node for a corporate network. Using KNOPPIX, I can easily create the CD. The problem starts when I try and activate the VPN solution.

It is a 2 step process. First the VPN gets set up (which requires user input) and then a small perl-Tk runs which asks them the IP address of the Windows Terminal Server they want to connect to, which then runs rdesktop in full screen mode. Viola, they can work at home as if they were sitting at their desk in the office. All the user will ever see is my two scripts (vpn questions and server IP questions) - not even a KDE or Gnome window manager gets started.

The VPN client will not accept username and pass on the command line, so it must be interactive. Secondly, the client does NOT return control to the terminal (prompt does not come back). Once the VPN is active, it does respond to a cntrl-z, bg command set, however.

So, I can easily write a nice perl-tk to ask their username and password, but how do I then run the vpn client and make it think that the it's being passed those data by the user, and not a script? Secondly, how do I know when the VPN client process is complete and running so I can move on to asking for the WTS/RDP server info from the user?

VPN client asks for: Username[<default>]:
then it asks: Pin and SecurID:
If accepted, it spits out some text about secure systems and finishes with a yes/no acceptance query: [y/n]:

At that point I need the VPN process to be backgrounded and the script to move on to my other IP Server questionare script (which already works).

Any help would be greatly appreciate, since even in my heavy perl days I was never that involved with process manipulation.


What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"

Replies are listed 'Best First'.
Re: Backgrounding interactive processes
by hbo (Monk) on Jul 25, 2004 at 22:50 UTC
    Assuming the VPN startup uses stdin/stdout, you can use the Expect module to converse with it. To background it, you can send it the STOP signal: kill $SIG{STOP}, $pid; To have it continue send the CONT signal: kill $SIG{CONT},$pid;. You can get the pid from the spawn method of expect. Or, you could issue the ^Z/bg commands via Expect, which sounds simpler, on reflection.

    As to knowing whether it has succeeded or not, you probably need to come up with a test based on the ability to connect to a VPN protected resource, like the DNS servers for instance.

    Update: Doing job control with Expect will only work if the command you spawn is a shell with job control, and not the VPN command itself. So you would spawn the shell, and then exec the VPN command with a send to the shell. It may not be simpler to do this compared to spawning the VPN command itself.

    "Even if you are on the right track, you'll get run over if you just sit there." - Will Rogers