How to check if remote directory exists using Net::SSH::Perl

Viewed 110

Check to see if remote directory exists using Perl Net::SSH::Perl

I want to check if a directory exists on a report server using the Net::SSH::Perl module.

This command works:

my($stdout, $stderr, $exit) = $ssh->cmd("ls -al /home/mydir");

But how can I do like:

if ( ! -e "/home/mydir/mydir_1" ) {
   mkdir "/home/mydir/mydir_1";
}

Any way to do this using this Perl module?

1 Answers

The -p option for mkdir accomplishes what you want (no error if existing), so something like:

my($stdout, $stderr, $exit) = $ssh->cmd("mkdir -p /home/mydir/mydir_1");
Related