Simple open remote file script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple open remote file script
# 1  
Old 03-12-2009
Simple open remote file script

I use Rsync to copy files to a remote folder in a command like this
Code:
rsync -aNPHAXxrvh --protect-args --fileflags --force-change --delete $file user@remotehost:/Volumes/backup

That works great with passwordless key exchange Smilie

Now I'm trying to open a remote file using this command
Code:
ssh -q user@remotehost "open /Volumes/backup/"file name"

This works great but if the file name contains spaces it gives me an error file doesn't exist. Is there a way I can open a remote file that contains spaces?
# 2  
Old 03-12-2009
Enclose the file name in single quotes inside the outer quotes. Alternatively, enclose the filenamein double quotes but you'll need to escape them with a backslash (\) to protect them from the calling shell.
# 3  
Old 03-12-2009
You are right but, how can I make the computer automatically replace the space with \space.
Code:
ssh -q user@remotehost "open /Volumes/backup/file\ name"

This works but I need to automate replacing the space with "\space" when needed. The reason for this is that I'm going to upload the files and then open it, I can't predict if they path on the remote folder is going to have spaces.
# 4  
Old 03-13-2009
As advised by JerryHone, you can do this:

Code:
ssh -q user@remotehost "open /Volumes/backup/\"${file}\""

Then it doesn't matter whether filename ($file) has spaces or not.
# 5  
Old 03-14-2009
WOW Thanks a Million. I'm not sure how it works but it does.
# 6  
Old 03-15-2009
Quote:
Originally Posted by elbombillo
WOW Thanks a Million. I'm not sure how it works but it does.
Well, suppose your filename is "file name.txt" (has a space). if you just put it as ssh -q user@remotehost "open ${file}", then first the local shell (from where you are running the command) will expand the name. So the command which will be passed to the remote machine will be "ssh -q user@remotehost open file name.txt". Obviously this will try to open a file called "file" instead of "file name.txt". So the trick is to ensure that we provide an extra set of double quotes (which preserve the space) and they are part of the command send to remote machine. But if we simply put the double quote, the local shell will interpret them. So we escape the double quotes (and avoid them from being interpreted by the local shell) by adding a \ before them. So the command which gets passed to the remote shell is:

ssh -q user@remotehost open "file name.txt"

This is what you want.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

2. Shell Programming and Scripting

How run simple command in xterm, and leave open?

I have written a simple script to show battery life remaining. I would like to be able to quickly view it with a predefined keybinding or launcher. xterm -e scriptname should do the trick but the xterm closes when the script finishes, not giving me chance to read the output. How can I keep... (3 Replies)
Discussion started by: spoovy
3 Replies

3. Shell Programming and Scripting

Perl open a remote shell

Hello , I am writing a script which takes the user name , password and hostname from the database and login to the server . I am only able to login to the server and my script logs out and only I can run few command if I provide those command in my script else I am not able to run those... (11 Replies)
Discussion started by: pratapsingh
11 Replies

4. UNIX for Dummies Questions & Answers

How to Know is a Remote hosts have open port

Hi gurus of unix!!!!, I have a little question. I nedd your helps The scenarios is the following I have tree equipment that are installed in different places. I use a carrier to interconnect the equipment. Some Port's (TCP) need to be open for an application that must be function correctly. For... (3 Replies)
Discussion started by: andresguillen
3 Replies

5. Shell Programming and Scripting

Open n number of remote sessions

I m need of something useful to reduce my n number of login sessions to save my time. Scenario : I will login 40+ servers daily with ip address. i hv generated ssh key gens in order to avoid passwords. what i need is : when i click a terminal, i need these 40 servers logged in... (1 Reply)
Discussion started by: anand.linux1984
1 Replies

6. Shell Programming and Scripting

Simple Find file Script.....

Im trying to make a very simple find the first file with the .zip extension in a specific folder and open that file. The folder path and file name will vary every-time and it may contain spaces. If I try to look For this example the folder directory is /Users/username/Desktop/testfolder/abc... (6 Replies)
Discussion started by: elbombillo
6 Replies

7. Solaris

Unable to open remote connections

Hello everybody, This is an unusual problem that I am facing on my Solaris 9 on Sun Blade 150 workstation. I can ping remote machines (outside subnet) but I can't open up a connection/port on those machines. For example, `ping ftp.xyz.com` gives ftp.xyz.com is alive but if I do a `ftp... (1 Reply)
Discussion started by: red_crab
1 Replies

8. Shell Programming and Scripting

Simple file checking script

Hi, I have a really, what I hope is, simple question. I'm looking for a simple way to see whether a file exists or not and then perform an action based on whether it exists or not. An example of what I tried is as follows: if then { echo "File mysql exists" ... (1 Reply)
Discussion started by: _Spare_Ribs_
1 Replies

9. Shell Programming and Scripting

Script to look for data in a file (not that simple) ...

I'm looking for a script or program that would allow me to pass a pattern to it and give me locations on where text appears in a file. I wish it was that straight forward (I would use egrep or something) Say I have the word in my text file "SUDAN" but my user does a search for "SUDANESE". Grep... (6 Replies)
Discussion started by: gseyforth
6 Replies

10. UNIX for Dummies Questions & Answers

Remote Connect - SCO Open Server

Hello.. Please helppppppp...!!! I am using SCO Open Server version 5.0 at work. I am trying to find a third party software to use on my computer at home which has windows 98 on it to do remote connect to my work. Is there any such software ? I know there is PC ANYWHERE but i don't think it... (2 Replies)
Discussion started by: jackpotp
2 Replies
Login or Register to Ask a Question