1

I have a shell script that accepts directory inputs. One of the directories I want to process is at a remote location. I am able to ssh into the remote host but I want to be able to reference the remote directory in a similar manner as a UNC path on Windows (in Windows you can type "\[remote host][share]" and reference that path in batch files). Is there a clean way to do a similar thing with ssh on Unix? When I call the shell script, I want to be able to type something like:

./run_shell_script.sh ssh://<host>/<path>

instead of running extra commands just to process that one directory? This is being done on a list of directories in a loop, so I don't want to have special code for remote directories.

4
  • What does your script do? Commented Feb 27, 2013 at 19:13
  • Well essentially it ends up calling a Perl script that accepts directory inputs. It parses log files and generates a report about them. Commented Feb 27, 2013 at 19:15
  • the directory has log files in it? im asking to know if it's a valid thing what you what, sound weird to me and maybe there is another solution Commented Feb 27, 2013 at 19:17
  • Yes it has log files. Commented Feb 27, 2013 at 19:19

1 Answer 1

1

One of possible solutions is to parse the URI like this:

_uri=ssh://host/path/to/file
_host=`echo $_uri | sed 's|^ssh://\([^/]*\)/.*$|\1|'`
_dir=`echo $_uri | sed "s|^ssh://$_host/\(.*\)\$|\1|"`

and then just to use these variables to ssh:

scp $_host:$_dir $local_dir

Also, sshfs may be interesting for you: it allows to mount a remote host into a directory on the local machine without the NFS administration burden and even root privileges.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.