RE: Writing output of a Shell command directly to a file

From: Luke Bakken (Luke.Bakken_at_getronics.com)
Date: 03/17/04

  • Next message: Josimar Nunes De Oliveira: "Fw: traps in perl"
    Date: Wed, 17 Mar 2004 11:07:40 -0800
    To: "tyohn" <tyohn@alabanza.com>, <beginners@perl.org>
    
    

    > Luke,
    >
    > Nope, this was the exact thing we were trying to get away
    > from. Suppose I
    > don't have space to store that file on the host box. We're
    > doing it in
    > stages now and I really want to get away from that since it
    > increases disk
    > activity on the host box during a full backup. Considering
    > these are web
    > servers I want to keep the disk activity as low as possible during the
    > backup, if for nothing else than saving the wear and tear on
    > these disks
    > that are spinning 24/7/365 as it is. We almost moved the
    > gzip to the backup
    > server also but then we decided that that would put too much
    > burden on the
    > backup server it's self (since the backup server may actually
    > be backing up
    > multiple servers at a time). I can do this on the command line with a
    > simple:
    >
    > ssh 1.1.1.1 "tar -cf - /home/$user | gzip" > /tmp/$user.tar.gz
    >
    > It seems to go straight to disk then, but I didn't like the
    > idea of using
    > that type of redirect here (and I'm not even sure if it's
    > possible to do
    > that properly in a perl script, besides that's not a very
    > 'perl' way of
    > doing it :-).

    Well, the Net::SSH module is only a wrapper around the ssh program, and
    it currently doesn't support sending the output of the command to a
    file. If you look in the SSH module at the ssh() routine, you'll see
    that it actually uses system() to run your command:

    sub ssh {
      my($host, @command) = @_;
      @ssh_options = &_ssh_options unless @ssh_options;
      my @cmd = ($ssh, @ssh_options, $host, @command);
      warn "[Net::SSH::ssh] executing ". join(' ', @cmd). "\n"
        if $DEBUG;
      system(@cmd);
    }

    You could hack the above to do what you want, for instance if you add a
    filehandle as an argument it could write ssh's stdout to that
    filehandle.

    Now, with the Net::SSH::Perl module, you might be able to use the sock()
    routine to write/read data:

    use Net::SSH::Perl;
    my $ssh = Net::SSH::Perl->new('1.1.1.1');
    $ssh->login($user, $pass);
    my $socket = $ssh->sock();

    # do stuff with socket here - write your command to the socket, and read
    the response to a file

    Luke


  • Next message: Josimar Nunes De Oliveira: "Fw: traps in perl"

    Relevant Pages

    • How can I restrict incoming root rsync over ssh to specified command?
      ... will use rsync over ssh to pull certain directories from the ssh ... Here's an example of the command, ... Even with the server locked up in a room with no user ...
      (comp.os.linux.security)
    • Re: rsync and ssh simple question
      ... possible to tie an SSH key to a specific command on a remote server, ... For instance, when you run rsync over ssh, the local rsync command ...
      (RedHat)
    • Re: [Info-ingres] problems with ssh
      ... Check the SSHD log on the server for errors. ... ancient version of SSH, unfortunately. ... the command seems to have functioned - but just wont terminate and leaves a process hanging around. ... Duckman: You got anymore of those glues? ...
      (comp.databases.ingres)
    • Re: ssh: start vnc server remotely
      ... > I have x11vnc on my computer and I want to start the server using ssh ... > command in ssh and that command just runs on the computer I'm connected ... The only people for me are the mad ones -- the ones who are mad to live, mad to talk, mad to be saved, desirous of everything at the same time, the ones who never yawn or say a commonplace thing, but burn, burn, burn like fabulous yellow Roman candles. ...
      (comp.os.linux.misc)
    • RE: Backups, VSS and SBS2003 HELP NEEDED!!!
      ... backup running, since we have nothing to fall back on should anything go ... We are not running anything fancy on the server. ... Copyright 2001 Microsoft Corp. ... > Please open a command window and execute the following commands ...
      (microsoft.public.windows.server.sbs)