1846734 Members
3852 Online
110256 Solutions
New Discussion

Re: tar directories

 
Goran Bulut_1
Advisor

tar directories

Hi all,

I have directories t0001-t9999 and 10000-99999.
I would like to do script to tar each directory they should keep same name e.g t2222--t2222.tar and so???and transfer them trough ftp to the \\comp_name\folder_name.

Thank you in advance

Goran
4 REPLIES 4
harry d brown jr
Honored Contributor

Re: tar directories


Why not just use the utility designed to do just that???????

rcp

or the secured

scp


why waste your time with tar, xargs, perl, ftp, ... ???


live free or die
harry
Live Free or Die
Magic_Wand
Advisor

Re: tar directories

Goran,

here's one method. It combines the tar and ftp in one swoop:

# get a name of the directories only
# then strip out the trailing "/"
parentDirectory=`ls -p | grep "/" | sed -e 's/\///g'`

# Go through each directory and tar it up with the ".tar" extension
for childDirectory in ${parentDirectory}
do
tar -cvf ${childDirectory}.tar ${childDirectory}
done

# Start the automatic ftp transfer
ftp -n $FTP_Server << endOfTransfer
user "$userName" "$password"
cd $PATH
bi
ha
prompt
mput *.tar
quit
endOfTransfer
================================
SELECT * FROM users WHERE clue > 0
Brian M Rawlings
Honored Contributor

Re: tar directories

Goran: It looks like you are trying to FTP these tar files to Windows, based on your destination. If that is the case, I don't know that rcp or scp will work (the windows box would have to have services and sanity to handle RPCs from Unix... possible, but not automatic).

I suspect, however, that it would be fairly straightforward to script up what you need, depending on the details, of course. Some interesting combination of using 'find' to get the name of each directory, piped to 'tar -cvf', then piped to ftp... kinda fun, if you have spare time, and don't have a deadline of tomorrow.

This forum is not, alas, a script generation facility. It is possible that some such script exists, out in freeware land, but unless someone knows of one and can steer you towards it, this will not help you much. What this forum IS good for, and how it can help you, is if you have a specific question after attempting to script this up.

Try it yourself, a few diffent ways. Look at the man pages for 'tar', 'find', 'cpio', and related commands. Pay close attention to the examples, some of which show how to pipe these commands together to do the sort of thing you are needing. You will no doubt make some headway, learning a lot on the way.

When you run up against a specific issue in your efforts, post the question, get some ideas, apply to your script, repeat as necessary. We like to help, but we can't write this for you, it's got to be done on the machine where it runs, and connected to the network and PC that you will be using.

Alternatively, if you are more of a windows geek than unix geek, you might have better luck getting windows to accept RPCs from Unix, and find that 'rcp' or 'scp' make more sense, as Harry said earlier. I have no idea what that would entail.

Good Luck and best regards,
--bmr
We must indeed all hang together, or, most assuredly, we shall all hang separately. (Benjamin Franklin)
harry d brown jr
Honored Contributor

Re: tar directories


If you are trying to expose these to a windows server, just install cifs9000, which is samba, which is smb, which fools M$ machines into thinking that the fileshares are from another m$ machine.

live free or die
harry
Live Free or Die