Extracting into a remote directory | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Extracting into a remote directory

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-23-2013
kumarjt kumarjt is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 October 2013, 5:16 AM EDT
Posts: 41
Thanks: 3
Thanked 1 Time in 1 Post
Extracting into a remote directory

I need to fit in a module in my Korn Shell script which would extract file_archive.tar.gz residing in the folder /apps/Test of my local machine into a folder /global/ in a remote machine server1.

Please help me on this regard.

Thanks
Kumarjit.
Sponsored Links
    #2  
Old 02-23-2013
MattyV's Avatar
MattyV MattyV is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 24 May 2013, 6:11 PM EDT
Posts: 10
Thanks: 4
Thanked 2 Times in 2 Posts
Many ways to skin a cat...

Kumarjit, this really depends on the OS and way the remote directory is accessed.

For instance if you mount a remote windows box, I strongly recommend using gvfs to mount the remote local directory and file roller to decompress.

If it is a unix box, there are a few options. One would be to simply mount the remote file system.

In my example I create a directory underneath my operational directory, the directory is called "remote".
Next ..

Code:
echho 'test' > test.txt
tar -pczf name_of_your_archive.tar.gz test.txt
ls
name_of_your_archive.tar.gz  remote  test.txt

If the objective is to now deflate into remote...

Code:
cd remote
tar -zxvf ../name_of_your_archive.tar.gz
ls
test.txt

If it is not locally mounted you can use still other approaches.

Quote:
Originally Posted by kumarjt View Post
I need to fit in a module in my Korn Shell script which would extract file_archive.tar.gz residing in the folder /apps/Test of my local machine into a folder /global/ in a remote machine server1.

Please help me on this regard.

Thanks
Kumarjit.
Sponsored Links
    #3  
Old 02-23-2013
spacebar's Avatar
spacebar spacebar is offline
Registered User
 
Join Date: Oct 2009
Last Activity: 2 June 2014, 3:23 PM EDT
Location: spaceBAR Central
Posts: 440
Thanks: 0
Thanked 70 Times in 70 Posts
Quote:
Originally Posted by kumarjt View Post
I need to fit in a module in my Korn Shell script which would extract file_archive.tar.gz residing in the folder /apps/Test of my local machine into a folder /global/ in a remote machine server1.

If you are going from/to a *nix type os, you could do something like this to transfer the file and untar it:

Code:
#!/usr/bin/ksh
# script: example_scp_ssh.sh

# Transfer file to remote
scp -v -o IdentityFile=~/.ssh/id_rsa -o BatchMode=yes /apps/Test/archive.tar.gz user@remote:/global
rc=$?
if [[ $rc != 0 ]]    then
    print "***Error occurred transferring file...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
else
 print "***Successful transfer of file...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
fi

# Run cmd on remote
ssh_results=`ssh user@remote '. ./.profile;tar -zxvf /global/archive.tar.gz'`
print "${ssh_results}"

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replicate remote directory to local directory with ftp before4 Shell Programming and Scripting 3 02-19-2013 01:31 AM
Zipping a directory and extracting to another server. BrutalBryan Shell Programming and Scripting 3 12-28-2011 01:26 PM
FTP files from different directory from remote server to one directory in local dassv Shell Programming and Scripting 3 12-16-2011 10:01 AM
Extracting Directory From Path Drayol Shell Programming and Scripting 3 04-15-2011 10:05 PM
extracting a field from directory path ?????? skyineyes Shell Programming and Scripting 15 07-10-2007 12:42 AM



All times are GMT -4. The time now is 05:37 AM.