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

In many of my Perl projects, both personal ones, CPAN modules and work projects, I write code which tests to see whether a module has DWIMmed with respect to file creation: the file names, their paths and their content.

When the files are on my own box or on a server to which I have full privileges, there's no problem doing this.

But now I need to test whether code I write on one server properly creates directories and files on other servers which I can normally access only via SSHing to them. Moreover, once having SSHed to those servers, I often have to sudo to a special user to, for example, delete test files once my code has created them.

Right now I'm doing a lot of this manually, but it would be far more efficient and precise if I could automate the process within a test script.

I'm sure TMTOWTDI applies here. What are the ways other Monks have approached this problem? TIA.

Jim Keenan

Replies are listed 'Best First'.
Re: Testing the creation of new files over SSH connection
by Zaxo (Archbishop) on Jun 19, 2006 at 02:28 UTC

    Two basic approaches -

    1. Upload a cleanup script, say cleanup_tests.pl to reside on the target, and call it through ssh -2 user@target sudo cleanup.pl.
    2. Look at Expect, which can stand in for you in emulating a terminal session.

    After Compline,
    Zaxo

      With the caveat that option 1 will not work unless the remote sudoers file allows NOPASSWD on random uploaded scripts (definitely not recommended). Mildly less offensive is that your cleanup script contains the allowed sudo lines (again w/o a password). Of course, option two requires hard-coding passwords (equally icky).

      IMHO, the best option is to set up an ssh key for the user you need to log in as which can only execute a specific script. man sshd for details (link)


      The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
Re: Testing the creation of new files over SSH connection
by Plankton (Vicar) on Jun 20, 2006 at 02:25 UTC
    If your script can create the files without having to sudo why can't it delete them? And for automating ssh why not setup public keys with no pass phrase?
      Plankton wrote:

      If your script can create the files without having to sudo why can't it delete them? And for automating ssh why not setup public keys with no pass phrase?

      My script does a system call to one of the company's scripts. The latter handles all the fancy stuff internally; I am limited to supplying options to it. Since the latter doesn't delete the lock files (it simply overwrites them on the next pass, but must run as a privileged user), I have to somehow.

      As for the keys suggestion, I will have to discuss this with the sysadmins, as the place is very security conscious. Thank you very much.

      Jim Keenan