Solved

Check if remote files exist (shell script)

Posted on 2008-10-20
5
2,959 Views
Last Modified: 2013-12-26
Hello.

I've already searched, but found nothing...

I need a script that checks if remote file exists. Everything that I've found only relates to one particular file. I need to check if there are any files in a particular directory, that start by some string...

I've tried this, unsuccessfully:

if ssh -l "$USER" $POSM200 'ls "'/home/tplinux/SAPiDoc/export/wpubon/processado/WPUBON01*'" >/dev/null'; then
        echo "file '"/home/tplinux/SAPiDoc/export/wpubon/processado/WPUBON01*"' exists";
        exit;
else
        echo "file '"/home/tplinux/SAPiDoc/export/wpubon/processado/WPUBON01*"' doesn't exist";
fi

but I got the following error:
ls: /home/tplinux/SAPiDoc/export/wpubon/processado/WPUBON01*: No such file or directory
file '/home/tplinux/SAPiDoc/export/wpubon/processado/WPUBON01*' doesn't exist

The problem seems to be finding a remote command that accepts wildcards.

Any help would be appreciated.
0
Comment
Question by:rmdb
  • 3
5 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22756817
Hi,
wildcards are not your problem.
You have way too much  ' s and  " s in your ssh command.
Leave them all out and escape your asterisk with a \.
w
 
0
 
LVL 48

Accepted Solution

by:
Tintin earned 50 total points
ID: 22763682
What you need is:
if ssh $USER@$POSM200 "ls /home/tplinux/SAPiDoc/export/wpubon/processado/WPUBON01*" >/dev/null 2>&1
then
    echo 'file /home/tplinux/SAPiDoc/export/wpubon/processado/WPUBON01* exists'
    exit
else
    echo 'file /home/tplinux/SAPiDoc/export/wpubon/processado/WPUBON01* does not exist'
fi

Open in new window

0
 
LVL 48

Expert Comment

by:Tintin
ID: 22792313
Any reason for the B grade?
0
 
LVL 1

Author Comment

by:rmdb
ID: 22795949
Hi,

Sorry, no reason at all. I was filling the "accept solution", and put B instead of A, I was distracted... Any chance to change it?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22800021
You have to put an admin request in.  
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Hello to you all, I hear of many people congratulate AWS (Amazon Web Services) on how easy it is to spin up and create new EC2 (Elastic Compute Cloud) instances, but then fail and struggle to connect to them using simple tools such as SSH (Secure…
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question