Avatar of saibsk
saibsk
 asked on

running unix commmand on a remote box in perl

i am doing something like this in a perl script

 my @files=`ssh $machine "ls $DIR/TEST[A-Z]*_[0-9].txt 2>/dev/null"`;

but gives me this error

ls: /home/devn/Test[A-Z]*_[0-9].txt: No such file or directory. Please advise

I dont have the net::ssh installed and i dont have the perms to install it.
Perl

Avatar of undefined
Last Comment
oheil

8/22/2022 - Mon
oheil

Perhaps no file exists matching your patterns.
Try the same command without patterns and filter the result using perl:
my @files=`ssh $machine "ls $DIR/"`;
foreach my $file (@files){
  if( $file =~ /TEST[A-Z]*_[0-9]\.txt/ ) {
    push(@good_files,$file);
  }
}
saibsk

ASKER
yes u were right there were no files. additionally how can i check whether the ssh with the command was successful whether it returned any files or not. Please advise
ASKER CERTIFIED SOLUTION
oheil

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes