1753906 Members
9155 Online
108810 Solutions
New Discussion юеВ

Re: Help with Script

 
Subbu Krishna
Occasional Advisor

Help with Script

Hello,

I am trying to write a script with the following requirements.

System A
---------

/hpm30/RCMO.dbf
/hpm31/RCMOtest.dbf
/hpm31/RCMOdata.dbf
/hpm32/RCMOlog.data

These directories also have other files that do not begin with RCMO.

I want to 'find' all files that begin with RCMO
in all the directories and 'tar' all the files
into a tar file which can be 'ftped' to the System B and untarred to the respective directories. These two systems are in two different locations and 'rdist' may not be an option. I get faster transfer rates with FTP.

System B
--------

/hpm30
/hpm31
/hpm31
/hpm32

Thank you - Subbu
9 REPLIES 9
linuxfan
Honored Contributor

Re: Help with Script

Hi Subbu,

One way of doing it is

find hpm* -name RCMO\* -exec tar rvf mydbf.tar {} \;

tar tvf mydbf.tar

In the find command you are looking for files starting with RCMO in directories starting with hpm.
Once the tar file is created, just check the contents using tar tvf.

Look at the man page for find, if you want more options.



-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
linuxfan
Honored Contributor

Re: Help with Script

Hi Subbu,

Looks like you asked the same question twice.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,11866,0x15f6c6af36b7d5118ff10090279cd0f9,00.html


-Ramesh
They think they know but don't. At least I know I don't know - Socrates
Tim D Fulford
Honored Contributor

Re: Help with Script

I answered the duplicat thread so here it is again

This does not answer you question directly, but it is what I would do.....

If you set up equivalences between the two systems you could do the xfr in one go & half the time!!!!

test equivalence on systemA, best as root, but oracle should also be OK
# remsh systemB ls

If this works
# tar cf - $(find -name RCMO\*) | remsh systemB "cd ; tar xf -"

It is important that is the same on both systems else it will untar it in the wrong directory (unless that is what you want). You could make / if you wish but the find will take longer & the untar will be absolute!

Lastly make sure before doing the above that the RCMO files will end up in the right disks/LV's else you'll fill up the wrong filesystem

I hope it all helps

Tim
-
Santosh Nair_1
Honored Contributor

Re: Help with Script

Unfortunately tar can not append to an archive if the archive doesn't already exist, so I think Ramesh's script would have a problem.

A workaround could be to get the list of files, again using the find command, and then creating the tar file at one shot, i.e.:

find /hpm* -name RCMO\* > archive.lst
tar cvf mydbf.tar $(cat archive.lst)

also you may want to consider compressing the archive so that it would be faster when you try to transfer it to another system, i.e.:

find /hpm* -name RCMO\* > archive.lst
tar cvf - $(cat archive.lst)|gzip -c > mydbf.tar.gz

Hope this helps.

-Santosh
Life is what's happening while you're busy making other plans
Wodisch
Honored Contributor

Re: Help with Script

Hello Subbu,

just a simple mixture of "find" and "tar" and
"ftp" should be fine:

tar cvf /tmp/all.tar $(find /hpm30 /hpm31 /hpm32 -name "RCMO*")

and then "ftp" it over and "tar xvf" it over
there.

HTH,
Wodisch
Sridhar Bhaskarla
Honored Contributor

Re: Help with Script

Subbu,

You can also try this simple way.

tar cvf /tmp/RCM.tar /hpm*/RCM*

FTP /tmp/RCM.tar to system B

and do

a tar xvf /tmp/RCM.tar

-Sri

You may be disappointed if you fail, but you are doomed if you don't try
Bill Hassell
Honored Contributor

Re: Help with Script

If this is a one-time task then the above suggestions should work if you have enough space to hold the tar archive.

However, if this is a regular task and (some of) these files are large then you could use a batch ftp to accomplish this task (assumptions: both systems have the named directories in $DIRS):

#!/usr/bin/sh

# replicate RCMO files in system B

REMOTECPU="myname.domain.com"
USER=somelogin
PW=somePW
DIRS="/hpm30 /hpm31 /hpm32"

for MYDIR in 30 31 32
do
/usr/bin/ftp -n -v << EOF
open $REMOTECPU
user $USER $PW
lcd $DIRS
cd $DIRS
prompt
binary
mput RCMO\*
bye
EOF

done

--

The RCMO\* needs the \* to prevent the shell's file matching from substituting anything in the local directory where the script is run. We want ftp to see the *, not the shell, since ftp must perform the match.



Bill Hassell, sysadmin
linuxfan
Honored Contributor

Re: Help with Script

Hi,

My suggestion would work if you are using gnu tar, but since that is not a valid assumption i guess you will have to create a list of contents or use one of the other suggestions.

Also i would like to add, you are better of compressing the tar file, to reduce the data to be transfered. Ofcourse you can script all this in one script, to tar, compress, ftp and then telnet to the other system, uncompress and untar the file and remove the tar file after the untar.

-Regards
Ramesh
They think they know but don't. At least I know I don't know - Socrates
linuxfan
Honored Contributor

Re: Help with Script

Hi Subbu,


Here is a script that you can modify or use it as it is to tar,uncompress, ftp , telnet to the remote machine, uncompress/untar the file and then delete the tar file on the remote/local machine.


/Begin/

#!/usr/bin/sh

PATH=/usr/bin:/usr/contrib/bin

# Here remote is your remote host
REMOTE=remote

# user is the user you want to ftp as
USER=user

# password of the user
PW=password

# Here /hpm3 can be an absolute path /path/to/hpm3,
DIR=/hpm3

# Files you want to copy to remote host
FILE=RCMO*.dbf

# Name of the tar file
MYTAR=mydbf.tar

#### Do not need to edit below #####

echo " ### Creating the tar file ### "
tar cvf $MYTAR /$DIR*/$FILE
echo " ### Compressing the tar file ### "
gzip $MYTAR


echo "### Transferring the compressed tar file to $REMOTE host ###"
ftp -n -v << EOF
open $REMOTE
user $USER $PW
cd $DIR
prompt
binary
put $MYTAR.gz
bye
EOF

echo "### Logging into the remote host for uncompressing/untarring the file ###"
(sleep 5
echo $USER
sleep 5
echo $PW
sleep 15
echo "gzip -dc $DIR/$MYTAR.gz | tar xvf - "
echo "rm $DIR/$MYTAR.gz"
echo exit) |telnet $REMOTE

echo "### Deleting the tar file on local host ###"
rm $MYTAR.gz

/End/


-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates