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.
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.
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 ..
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...
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.
If you are going from/to a *nix type os, you could do something like this to transfer the file and untar it:
#!/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}"