1

My Jenkins pipeline runs from Linux machine and I want to check if Windows shared path like - '\\domain\parent\child\grand-child\ exists or not through shell script.

If same was to run from Windows machine, then following would have helped -

if exist <windows-shared-path> echo "Path present"

Could you please share linux command to achieve this i.e. if windows shared path exists from Linux machine?

3
  • 1
    Is that remote path mounted to the linux machine?
    – jesse_b
    Jun 23, 2021 at 12:05
  • Try smbclient. If the path is a directory: if smbclient //server/share PASSWORD -c "cd child/grandchild"; then echo success; else echo nope; fi. If not, use ls instead of cd. Jun 23, 2021 at 12:26
  • @jesse_b, no it is not mounted. Wanted to check if it is possible without mounting.
    – Alpha
    Jun 24, 2021 at 8:56

2 Answers 2

0

You could use smbclient like this:

 smbclient -U'<domain>\<user>%<password>' '\\server\path\to\dir' -c exit && echo exists || echo does not exist

I.e. smbclient will fail or succeed depending on availability of the given location and return an exit code of 0 or 1, respectively. By directly issuing exit as command, we do nothing on the share itself.

0

@FelixJN answer did not work for me, smbclient with \\server\path\to\dir connects to \\server\path, not \\server\path\to\dir then always success if at least \\server\path exists, that said, inspired from this, I used -D in addition, well replacing \ by / since else I got tree connect failed: NT_STATUS_BAD_NETWORK_NAME error, and also escaping \ for -U option:

smbclient -U'<domain>\\<user>%<password>' '//server/path/' -D 'to/dir' -c exit && echo exists || echo does not exist

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .