[lug] cp and rm

Chip Atkinson catkinson at circadence.com
Tue Jul 31 16:31:09 MDT 2001


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

For your function tarandgzip, why not just use the -z option to tar such 
as tar cvzf?

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)

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

Chip



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  "Tue Jul 31 15:40:10 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




More information about the LUG mailing list