Hi everyone I'm not to ksh. What i'm trying to do is I'm writing a script to scp a(or many) zip file from a local directory to a remote host. Then get the script to ssh into the remote host to gunzip the files I just scp over. Is there any simple way to do this. I keep trying but once I ssh over to the remote host the rest of my commands no longer run like the cd /file/directory and then gzip -d /files etc.....
Asked
Active
Viewed 106 times
0
-
1possible duplicate of [how to use ssh to run shell script on a remote machine?](http://stackoverflow.com/questions/305035/how-to-use-ssh-to-run-shell-script-on-a-remote-machine) – tripleee Jul 19 '13 at 15:16
-
Show us the exact commands that you used. – Henk Langeveld Jul 21 '13 at 10:46
-
I actually figured it out before i had it something like ssh user@host on one line then gzip -d on the next line and it wouldn't gunzip after I connected through ssh. So what I did was have the ssh and gzip command on the same line and it worked – J. L. Jul 22 '13 at 14:25
1 Answers
0
NB: don't confuse "zip" and "gzip", two different animals
This should work:
cd <local_directory>
# collect files names as $1 $2 ... $N
set -- *.gz # or use your own filter like "dumps*.gz"
# put source file a tar archive and send it as input to ssh
# then, on the other side, untar the file then decompress
tar cf - $* | ssh <user>@<remote_host> "cd <remote dir> && tar xf - && gunzip $*
Note: using "&&" instead of ";" to prevent "tar" command to be executed if "cd" fails for any reason

Gilles Pion
- 166
- 1
- 8