[lug] cp and rm

David dajo at frii.com
Wed Aug 1 09:29:31 MDT 2001


Chip, Thank you very much for the response.  You may detect some
frustration in what follows, please do not think that it is directed
at you, it ain't.

   I believe that if you use /bin/rm or /bin/cp you don't have any alias 
   problems to worry about.

I shall try this; but, if it works, it dodges what I perceive as one
of the real problems, namely a lack of consistency.  As a general rule
- there are exceptions - having something work and then not work is
plain lousy; and, furthermore, will soon have Linux, in the large,
down to M$ standards.  I write "in the large" to mean what a user gets
and thinks of when he installs "Linux", i.e., a distribution.  I note
that I have seen a number of postings about RH7.1 on the list.  I have
a fairly low opinion of the quality of RedHat software, although cp
and rm probably are not theirs.  I should dump it and go to another
distribution, but I subscribed to KRUD for a year.  Fortunately the
kernel seems to be considerably better than the stuff on top.
   
   For your function tarandgzip, why not just use the -z option to tar such 
   as tar cvzf?

I have never thought about doing it that way; who cares?  Especially
since what I have work(s)(ed).  I just want to get a valid copy of
important work onto another disc (I put it on another machine as
well).  I like elegance, but it is a very distant second to
correctness and consistency for me (which, of course, have their own
elegance 8-).
   
   Your function would be something like:
   tgzip ()
   {
      echo "starting tgzip"
      date
      echo "tarring $1"
      /bin/rm -f $1
      tar -cvzf $1 $2
      date
      echo "Done"
   }
   You may also wish to temporarily save the file you are removing in case 
   the tar command fails.  You can check the success of the command with 
   the $? variable like so.
   tar -cvzf $1 $2
   if [ $? ]; then
      echo failed
   else
      echo succeeded
   fi
   (In your case you would probably restore the temporarily saved file)

This is all just plain not worth it to me; I can check the directory
with ls.  I did consider these things when the functions were written.
The simple versions do/did the job, and that is all that I need.
Occam's razor came up earlier this week, as did discussion of simple
vs complex firewalls; I like KISS.

   I'm kind of surprised that you would see the multiple mounts.  I've 
   never seen that before.  You could do the following for that though:
   
   ismounted=$(mount | grep Archive2)
   if [ -z "$ismounted" ]; then
      mount /Archive2
   fi

I did this:
Rednose root ~ umount /Archive2
umount: /dev/hdc7: not mounted
umount: /dev/hdc7: not mounted
umount: /dev/hdc7: not mounted
umount: /dev/hdc7: not mounted
umount: /dev/hdc7: not mounted
umount: /dev/hdc7: not mounted
umount: /dev/hdc7: not mounted
umount: /dev/hdc7: not mounted
umount: /dev/hdc7: not mounted
umount: /dev/hdc7: not mounted

and df then produced what it should.  So, the abort code is not
unwinding properly and leaves stale information for df to pick up.

   Chip

You may be interested in this, which is about where I am right now.  The code
below works (I have since chnaged the -Rf to Rpf); now I have to decide if I
changed something recently and have forgotten about it.  Unfortunately, the
evidence is destroyed.  Is "cp -af /home/bozo /Archive2/home/." actually
wrong?  It produced "cp: omitting directory `/home/bozo'" which is hardly
informative.

backuphome  ()
    {
        echo "archive commencing"

        mount  /Archive2  

        echo  "copying to Archive2"
        cp  -Rf  /home/bozo            /Archive2/home
        cp  -Rf  /home/dajo            /Archive2/home
        cp  -Rf  /home/Nepenthes       /Archive2/home
        cp  -Rf  /home/NewSystemFiles  /Archive2/home
        cp  -Rf  /home/Releases        /Archive2/home

        tarandgzip  /Archive2/dajotar  /home/dajo
        tarandgzip  /Archive2/neptar   /home/Nepenthes

        umount  /Archive2

        echo  "archive complete"
    }

Rednose root ~ source ./.bashrc
Rednose root ~ df
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/hda5               466668     57697    384876  14% /
/dev/hda6               632444       848    599468   1% /tmp
/dev/hda7               466668     45146    397427  11% /var
/dev/hda9              2925300   1242552   1534152  45% /usr
/dev/hda10              790556    106944    643452  15% /usr/src
/dev/hda11             3162420    326760   2675012  11% /usr/local
/dev/hda12             9875100   1408744   7964728  16% /home
Rednose root ~ backuphome
archive commencing
copying to Archive2
starting tarandgzip
Tue Jul 31 17:28:47 MDT 2001
tarring /Archive2/dajotar
tar: Removing leading `/' from member names
gzipping /Archive2/dajotar
Tue Jul 31 17:28:59 MDT 2001
completed tarandgzip
starting tarandgzip
Tue Jul 31 17:28:59 MDT 2001
tarring /Archive2/neptar
tar: Removing leading `/' from member names
gzipping /Archive2/neptar
Tue Jul 31 17:29:04 MDT 2001
completed tarandgzip
archive complete
Rednose root ~ df
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/hda5               466668     57697    384876  14% /
/dev/hda6               632444       848    599468   1% /tmp
/dev/hda7               466668     45146    397427  11% /var
/dev/hda9              2925300   1242552   1534152  45% /usr
/dev/hda10              790556    106944    643452  15% /usr/src
/dev/hda11             3162420    326760   2675012  11% /usr/local
/dev/hda12             9875100   1408744   7964728  16% /home
Rednose root ~ mount /Archive2
Rednose root ~ dr /Archive2
total 13M
-rw-r--r--    1 root     root         9.6M Jul 31 17:28 dajotar.gz
drwxr-xr-x    7 root     root         4.0k Jul 31 17:28 home/
-rw-r--r--    1 root     root         3.0M Jul 31 17:29 neptar.gz
Rednose root ~ dr /Archive2/home/
total 20k
drwxr-xr-x    5 root     root         4.0k Jul 31 17:28 bozo/
drwxr-xr-x   30 root     root         4.0k Jul 31 17:28 dajo/
drwxr-xr-x   11 root     root         4.0k Jul 31 17:28 Nepenthes/
drwxr-xr-x    9 root     root         4.0k Jul 31 17:28 NewSystemFiles/
drwxr-xr-x    3 root     root         4.0k Jul 31 17:28 Releases/


David wrote:

> Is anyone having trouble with cp and/or rm under RH7.1(KRUD)?  I have
> scripts that have worked forever that now do not.  The problem (with
> both rm and cp) appears as though they have been set with xx='xx -i'.
> And this state persists despite all the counter measures that I can
> think of.  I.e., unalias xx, alias xx=xx, using the -f option, using
> the --remove-destination option (cp), etc.  When I am copying hundreds
> of files I prefer not to have to answer a prompt for each file 8-)
> 
> Also, I just did a df and found that (my bash function) has mounted my
> archive directory ten times (presumably I have run the function ten
> times, and I have been aborting with C-c); is that normal?  I recall a
> "xxxx already mounted" kind of message from the past.
> 
> Rednose root ~ df
> Filesystem           1k-blocks      Used Available Use% Mounted on
> /dev/hda5               466668     57695    384878  14% /
> /dev/hda6               632444       848    599468   1% /tmp
> /dev/hda7               466668     45138    397435  11% /var
> /dev/hda9              2925300   1242552   1534152  45% /usr
> /dev/hda10              790556    106944    643452  15% /usr/src
> /dev/hda11             3162420    326760   2675012  11% /usr/local
> /dev/hda12             9875100   1408696   7964776  16% /home
> /dev/hdc7               466668     57695    384878  14% /Archive2
> /dev/hdc7               466668     57695    384878  14% /Archive2
> /dev/hdc7               466668     57695    384878  14% /Archive2
> /dev/hdc7               466668     57695    384878  14% /Archive2
> /dev/hdc7               466668     57695    384878  14% /Archive2
> /dev/hdc7               466668     57695    384878  14% /Archive2
> /dev/hdc7               466668     57695    384878  14% /Archive2
> /dev/hdc7               466668     57695    384878  14% /Archive2
> /dev/hdc7               466668     57695    384878  14% /Archive2
> /dev/hdc7               466668     57695    384878  14% /Archive2
> 
> dajo
> 
> These are the functions that have worked in the past.
> 
> ##############################################################################
> #                                                                            #
> # .bashrc - root configuration file for Bash shell.                          #
> #                                                                            #
> # Hacked-up by dajo                                                          #
> # -last-modification-date  "Wed Aug  1 09:27:09 2001"                        #
> #                                                                            #
> ##############################################################################
> 
> 
> source /home/dajo/.bashrc
> 
> alias  emacs="/usr/local/bin/emacs -q -l /root/.emacs -g 159x69+130+20 &"
> 
> # FVWM2 seems to require this so that it can overwrite initialisation files.
> unset noclobber
> 
> # Necessary for some operations, e.g., make install for emacs.
> PATH=$PATH:/sbin
> 
> # Tool.
> tarandgzip  ()
>     # parameter 1 is the name of the file to be created.
>     # parameter 2 is the directory to be processed.
>     {
>         echo  "starting tarandgzip"
>         date
>         echo  "tarring $1"
>         rm    -f   $1
>         tar   -cf  $1  $2
>         echo  "gzipping $1"
>         gzip       $1
>         date
>         echo  "completed tarandgzip"
>     }
> 
> # Archive.
> backuphome  ()
>     {
>         echo "archive commencing"
> 
>         mount  /Archive2  
> 
>         echo  "copying to Archive2"
>         cp  -af  /home/bozo            /Archive2/home/.
>         cp  -af  /home/dajo            /Archive2/home/.
>         cp  -af  /home/Nepenthes       /Archive2/home/.
>         cp  -af  /home/NewSystemFiles  /Archive2/home/.
>         cp  -af  /home/Releases        /Archive2/home/.
> 
>         tarandgzip  /Archive2/dajotar  /home/dajo
>         tarandgzip  /Archive2/neptar   /home/Nepenthes
> 
>         umount  /Archive2
> 
>         echo  "archive complete"
>     }
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug

_______________________________________________
Web Page:  http://lug.boulder.co.us
Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug




More information about the LUG mailing list