Link to home
Start Free TrialLog in
Avatar of rmdb
rmdb

asked on

Check if remote files exist (shell script)

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.
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

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
 
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tintin
Tintin

Any reason for the B grade?
Avatar of rmdb

ASKER

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?
You have to put an admin request in.