How do I untar file through an ssh session?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How do I untar file through an ssh session?
# 1  
Old 05-27-2008
How do I untar file through an ssh session?

Hi All,

How do I untar (tar xvf) a file through an ssh session?

I have a tar file with "relative path names".
I scp the file to a remote host:/tmp - no prob.
But when I untar the file through ssh from a remote host
it puts it in my "home directory" under the relative path -
not in /tmp where I really want it to go.

Here it is:

$ set -o vi
$ tar tvf test.tar
drwxr-xr-x 992 205 0 May 23 15:14:44 2008 holdingArea/
drwxr-xr-x 992 205 0 May 23 15:14:42 2008 holdingArea/ccmig_1_00/
drwxrwxrwx 992 205 0 May 23 15:14:44 2008 holdingArea/stage/
drwxrwxrwx 992 205 0 May 23 15:14:54 2008 holdingArea/stage/ccmig_1_00/
drwxr-xr-x 992 205 0 May 23 15:14:53 2008 holdingArea/stage/ccmig_1_00/system/
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/system/system1.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/system/system2.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/system/system3.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/system/system4.txt
drwxr-xr-x 992 205 0 May 23 15:14:53 2008 holdingArea/stage/ccmig_1_00/utils/
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/utils/utils1.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/utils/utils2.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/utils/utils3.txt
-rwxrwxr-x 992 205 7 May 23 15:14:55 2008 holdingArea/stage/ccmig_1_00/utils/utils4.txt
drwxr-xr-x 992 205 0 May 23 15:14:54 2008 holdingArea/stage/ccmig_1_00/config/
drwxr-xr-x 992 205 0 May 23 15:14:54 2008 holdingArea/stage/ccmig_1_00/config/config1/
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config11.txt
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config12.txt
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config13.txt
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config14.txt
drwxr-xr-x 992 205 0 May 23 15:14:54 2008 holdingArea/stage/ccmig_1_00/config/config1/config2/
-rwxrwxr-x 992 205 7 May 23 15:14:56 2008 holdingArea/stage/ccmig_1_00/config/config1/config2/config21.txt
-rwxrwxr-x 992 205 7 May 23 15:14:57 2008 holdingArea/stage/ccmig_1_00/config/config1/config2/config31/config314.txt
. . . .
$ whoami
framrodjones
$ scp test.tar remotehost:/tmp
test.tar 100% 40KB 40.0KB/s 00:00
$
$ ssh remotehost tar xvf /tmp/test.tar
x holdingArea
x holdingArea/ccmig_1_00
x holdingArea/stage
x holdingArea/stage/ccmig_1_00
x holdingArea/stage/ccmig_1_00/system
x holdingArea/stage/ccmig_1_00/system/system1.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/system/system2.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/system/system3.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/system/system4.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/utils
x holdingArea/stage/ccmig_1_00/utils/utils1.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/utils/utils2.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/utils/utils3.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/utils/utils4.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config
x holdingArea/stage/ccmig_1_00/config/config1
x holdingArea/stage/ccmig_1_00/config/config1/config11.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config12.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config13.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config14.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config2
x holdingArea/stage/ccmig_1_00/config/config1/config2/config21.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config2/config22.txt, 7 bytes, 1 tape blocks
x holdingArea/stage/ccmig_1_00/config/config1/config2/config23.txt, 7 bytes, 1 tape blocks
. . . .
$

OK - looks good. But when I login to remotehost and cd /tmp there is
no holdingArea there.

If I cd ~framrodjones - bingo - the holdingArea is there.
But that's not where I want it. How to I untar the test.tar so that it installs
in the directory where I scp'd it?

Thanks, FramRodJones
# 2  
Old 05-28-2008
Code:
ssh remotehost (cd /tmp ; tar xvf test.tar)

or
Code:
ssh remotehost "cd tmp ; tar xvf test.tar"

depending on your shell.


Better yet though, why not stream it? That way you don't need to scp it first.
Code:
cat test.tar | ssh remotehost "cd tmp ; tar xvf -"

Taking the example even further:
Code:
cd /where/the/original/data/is ; tar -cf - . | ssh remotehost "cd tmp ; tar xvf -"

# 3  
Old 05-28-2008
Quote:
Originally Posted by Smiling Dragon
Code:
ssh remotehost (cd /tmp ; tar xvf test.tar)

or
Code:
ssh remotehost "cd tmp ; tar xvf test.tar"

depending on your shell.


Better yet though, why not stream it? That way you don't need to scp it first.
Code:
cat test.tar | ssh remotehost "cd tmp ; tar xvf -"

Taking the example even further:
Code:
cd /where/the/original/data/is ; tar -cf - . | ssh remotehost "cd tmp ; tar xvf -"


Totally cool.
I chose this: cat test.tar | ssh remotehost "cd tmp ; tar xvf -"

Works great! Thank you!Smilie
# 4  
Old 05-28-2008
hope you know when you ssh / telnet / rlogin as a specific user to a box, you are taken to that particular users home directory. In your case, you were taken to your home directory in the remore box and tar was extracting at the location you were at, while issuing the tar command Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to exit ssh session

Hi , I am running a script on multiple servers.When I run that script on one server,I want to exit from that server and want to go to next server.PFB script: Suppose there are 3 servers:server1,server2,server3.I am currently in server1. for h in {2..3} do ssh username@server$h <<EOF ... (4 Replies)
Discussion started by: sonu141
4 Replies

2. Red Hat

tar/untar over ssh

I use red hat linux. I have two linux server . I want to use tar over ssh to tar and untar the file. The server A , have IP 10.1.1.a ,there is dir a and contain files. The server B have IP 10.1.1.b , there is dir b and contain file . So, in above case ,how can I tar over ssh sunc that the file... (0 Replies)
Discussion started by: chuikingman
0 Replies

3. Shell Programming and Scripting

SSH session in perl.

Is it possible to ssh to a server in perl and execute multiple commands without doing them all at once? I know I can potentially do something like system( 'ssh user@server "cd directory; grep blah *; curl someurl.com"'); However, I'd like the functionality where I don't have to keep SSHing... (3 Replies)
Discussion started by: mrwatkin
3 Replies

4. UNIX for Dummies Questions & Answers

SSH session

I ran a job using SSH and then used screen command followed by space bar. Then I ran the job. But after some hours, the internet connection was lost.This had happened to me before. I used to run the whole job again. Today I came across the fact that I could restart the jobs without having to do it... (2 Replies)
Discussion started by: nellierd
2 Replies

5. Shell Programming and Scripting

SSH session saving

Hi, I want to execute some script on the remote session and transfer the processed file on remote machine to local machine. I tried with ssh-keygen and ssh-copy-id but seems that this has been disable on the remote machines, Is there any possiblity that I can save the remote username and... (7 Replies)
Discussion started by: maruthavanan
7 Replies

6. HP-UX

ssh session getting hung (smilar to hpux telnet session is getting hung after about 15 minutes)

Our network administrators implemented some sort of check to kill idle sessions and now burden is on us to run some sort of keep alive. Client based keep alive doesn't do a very good job. I have same issue with ssh. Does solution 2 provided above apply for ssh sessions also? (1 Reply)
Discussion started by: yoda9691
1 Replies

7. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

8. Shell Programming and Scripting

Finding out if you are in an ssh session

Hey, I'm trying to build customized behavior in a bash script for when it is run within an ssh session. This is how I'm finding out if the current session is ssh: USER=`whoami` ... (3 Replies)
Discussion started by: neked
3 Replies

9. Solaris

mbx_bad_handle during ssh -X session

We have a Solaris 10 server that we're migrating an old Cadre Teamwork application to. We find that when users on Sun workstations use ssh -X <username>@<new server> and run Teamwork on this new server it is fine. When cygwin users and linux users run ssh -X to get to this new platform they... (0 Replies)
Discussion started by: pzxkys
0 Replies

10. Shell Programming and Scripting

scripting an ssh session?

I know the root login/password for a machines, and I want to automate some commands like this from each: ssh root@remoteHost1 "tail /var/log/messages" ssh root@remoteHost2 "tail /var/log/messages" ssh root@remoteHost3 "tail /var/log/messages" ssh root@remoteHost4 "tail /var/log/messages" ssh... (2 Replies)
Discussion started by: jjinno
2 Replies
Login or Register to Ask a Question