Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: ^kazike^ en 19 Septiembre 2006, 21:53 pm



Título: script linux
Publicado por: ^kazike^ en 19 Septiembre 2006, 21:53 pm
Hola a todos. estoy haciendo un script en linux que hace backups de un directorio dado. Pero me pasaalgo curioso al ejecutar el script ademas de los archivos q yo tengo en el directorio siempre me aparecen otros con el mismo nombre y el signo ~. A que se debe esto?¿?
Este es mi codigo:
Código:
#!/bin/bash
##This script makes a backup of an especified directory
##Programmed by Raúl Sánchez

##I check the parameters

if [ $# -ne 1 ]
then
  echo You must enter a valid directory
  echo usage: $0 directory
  exit 1
fi

dir=$1    ##dir is the directory specified by the first parameter

## make sure $dir is a directory (not a file) and has write privilege
if [ ! -d $dir ] || [ ! -w $dir ]
then
  echo $dir not a writable directory
  exit 1
fi

##I enter into the directory
cd $dir

files=*
## variable files expands to include a list of all files
## in the directory

## examine all files in the directory
## to the user
for file in $files
do      ## take a look at every file
 if [ ! -f $file ]
 then  ## if not an ordinary file then skip
       continue  ## treat only ordinary files
 fi
 echo " " ## gives a blank line
 ls -l $file    ## list file and its attributes
 while [ 1 ]    ## infinite loop
   do 
     echo "***** Do you want to create a backup of $file??"
     echo -n "[y(yes), n(no)]"  ## " is necessary to avoid misinterpreting *
     read c 
     case $c in      ## what did user select
         
         y) ## yes -- I create the backup
            if [ ! -r $file ]
            then   ## can I read this file?
               echo cannot read $file
            else
               cp $file $file.bak  ##copy the file
               echo "***** $file saved"
            fi
            break;; ## to handle next file
         
         n) ## no, don't save file
            echo "***** $file not saved"
            break;; ## to handle next file
     esac
  done  ## while loop
done  ## for loop
exit 0

Gracias y Saludos


Título: Re: script linux
Publicado por: JuszR en 20 Septiembre 2006, 00:33 am
Los archivos que aparecen con ~ (o con la extensión .bak) son de backups. :)


Título: Re: script linux
Publicado por: ^kazike^ en 20 Septiembre 2006, 02:47 am
Ah pero aparecen a parte de los backups q yo quiero hacer, de hecho mi script me pregunta si quiero hacer backups d ellos