30 Oct, 2025 - 04:37 PMDeutsch | English
Hola invitado [ Register | Entrar ]

Publicar nuevo tema   Responder al tema
Ver tema anterior Versión imprimible Entre para ver sus mensajes privados Ver tema siguiente
Autor Mensaje
Dannyboy
Asunto: apt-get Skript (Loop, Schleife)  MensajePublicado: 15 Jun, 2008 - 08:01 PM



Registrado: 30 Jun, 2005
Mensajes: 449

Mhm,
irgendwie ist das komisch. Ich lese Packages aus einer Datei und kann diese via echo regulär ausgeben, doch wende ich apt-get install auf ein Package an, so wird es installiert und die Schleife nach der ersten Package-Installation abgebrochen. Das würde ich sehr gerne vermeiden und vorallem verstehen. Winken

Hier der 3-Zeiler:
Código:
# $1 ---> Eingabedatei, in der die Packages aufgelistet sind
while read FILE; do
  echo "installing $FILE ..."
  if apt-get install -y "$FILE" >> /dev/null 2>&1; then
    echo "--> $FILE was installed"
  else
    echo "--> Could not install $FILE"
  fi
done < "$1"


Greetz
Dannyboy
 
 Ver perfil de usuario Enviar mensaje privado  
Responder citando Volver arriba
Dannyboy
Asunto:   MensajePublicado: 16 Jun, 2008 - 07:13 PM



Registrado: 30 Jun, 2005
Mensajes: 449

Ich kann nicht glauben, dass ich bisher der Einzige bin, der versucht hat Pakete in einer Schleife zu installieren. Geschockt

Greetz
Dannyboy
 
 Ver perfil de usuario Enviar mensaje privado  
Responder citando Volver arriba
Kano
Asunto:   MensajePublicado: 16 Jun, 2008 - 07:24 PM



Registrado: 17 Dic, 2003
Mensajes: 16809

Ach installier dir einfach aptitude, das ignoriert fehlende Pakete.
 
 Ver perfil de usuario Enviar mensaje privado  
Responder citando Volver arriba
Dannyboy
Asunto:   MensajePublicado: 17 Jun, 2008 - 09:20 PM



Registrado: 30 Jun, 2005
Mensajes: 449

Hi Kano,
ich wollte ja das Problem vor allem versehen. Scheint als wird STDIN leer gesaugt und die Schleife deshalb beendet. Hab' nun ein Work-Around mit <xargs> geschrieben, so dass es funktioniert. Sehr glücklich

Código:
#!/bin/bash

INSTALLED="$HOME/apt_installed.info"
NOT_INSTALLED="$HOME/apt_not_installed.info"

[ "$UID" -ne "0" ] && false_exit "You must be root to use this script"

function false_exit () {
  echo "$1"; echo "breaking up."; exit 1
}

[ -r "$1" ] || false_exit "Cannot read file $1"
touch "$INSTALLED" "$NOT_INSTALLED" > /dev/null 2>&1
[ -w "$INSTALLED" -a -w "$NOT_INSTALLED" ] || false_exit "could not create logfiles in $HOME"
#[ $(ping -c 1 "google.de" > /dev/null 2>&1) ] || false_exit "internet connection not active"
echo "Updating debian-sources ..."
if ! apt-get update; then
   false_exit "an error occured while updating debian-sources. Please fix this issue and run this script again"
fi

while read FILE; do
  echo "installing $FILE ..."
  if echo "$FILE" | xargs apt-get install -y >> /dev/null 2>&1; then
    echo "--> $FILE was installed" | tee -a "$INSTALLED"
  else
    echo "--> Could not install $FILE" | tee -a "$NOT_INSTALLED"
  fi
done < "$1"

echo "Logfiles for installed and dropped packages are:"
echo " - $INSTALLED"
echo " - $NOT_INSTALLED"
echo "operation is done"


Greetz
DANNYBOY
 
 Ver perfil de usuario Enviar mensaje privado  
Responder citando Volver arriba
Kano
Asunto:   MensajePublicado: 17 Jun, 2008 - 10:23 PM



Registrado: 17 Dic, 2003
Mensajes: 16809

done <<EOT
$(cat "$1")
EOT

hätte es wohl getan. Aber dein script ist insofern sinnlos, wenn du nicht die installierten bzw. nicht installierten Pakete loggst. Wennst es einfach nur installieren willst ist aptitude einfacher.
 
 Ver perfil de usuario Enviar mensaje privado  
Responder citando Volver arriba
Mostrar mensajes anteriores:     
Cambiar a:  
Todas las horas son GMT + 1 Hora
Publicar nuevo tema   Responder al tema
Ver tema anterior Versión imprimible Entre para ver sus mensajes privados Ver tema siguiente
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Créditos
 
Deutsch | English
Logos and trademarks are the property of their respective owners, comments are property of their posters, the rest is © 2004 - 2006 by Jörg Schirottke (Kano).
Consult Impressum and Legal Terms for details. Kanotix is Free Software released under the GNU/GPL license.
This CMS is powered by PostNuke, all themes used at this site are released under the GNU/GPL license. designed and hosted by w3you. Our web server is running on Kanotix64-2006.