elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  script linux
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: script linux  (Leído 3,750 veces)
^kazike^

Desconectado Desconectado

Mensajes: 88



Ver Perfil
script linux
« 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


En línea

JuszR


Desconectado Desconectado

Mensajes: 2.866


Programming & RI


Ver Perfil
Re: script linux
« Respuesta #1 en: 20 Septiembre 2006, 00:33 am »

Los archivos que aparecen con ~ (o con la extensión .bak) son de backups. :)


En línea

- No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes. [Herbert Mayer]
^kazike^

Desconectado Desconectado

Mensajes: 88



Ver Perfil
Re: script linux
« Respuesta #2 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
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Script para Prompt contra Linux
Scripting
deskicio83 2 3,842 Último mensaje 21 Enero 2011, 09:27 am
por deskicio83
LINUX Script
Scripting
Tinker08 1 1,715 Último mensaje 17 Julio 2012, 08:00 am
por leogtz
Error en script en Linux
Scripting
Straufen 5 9,862 Último mensaje 7 Abril 2013, 14:43 pm
por dato000
Script de mantenimiento en Linux con Python3
GNU/Linux
Iluminadora 0 1,882 Último mensaje 19 Enero 2015, 02:52 am
por Iluminadora
problema en script linux
Scripting
almorace 2 2,093 Último mensaje 4 Junio 2016, 21:58 pm
por k0n3
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines