Ale-x
bash lehrling
ich hab mir nen script gebastelt und hätte gerne verbesserungsvorschläge was man anders machen könnte vielleicht kann es sogar der eine oder andere gebrauchen
http://www.ale-x.com/ncprof
sollte selbsterklärend sein durch die hilfe????
http://www.ale-x.com/ncprof
sollte selbsterklärend sein durch die hilfe????
Code:
#!/bin/bash
#code by ale-x
#[url]www.ale-x.com[/url]
#teile verwendet von ifswitch (ge.mine.nu)
#filename#ncprof
clear
##############auch mit root das script nutzen koennen? dann diesen teil auskommentieren############
if [ "$USER" = "root" ]
then
echo
echo
echo
echo "Du bist als root angemeldet, ein user account wird empfohlen"
exit
fi
###################################################################################################
CONFDIR=$HOME/.ncprof/ #kann angepasst werden
PROFIL=$2 #nicht aendern
FILE=$3 #nicht aendern
DIR=$4 #nicht aendern
LOCALDIR="`pwd`" #nicht aendern
if [ ! -n "`which ncftp`" ] || [ ! -n "`which ncftpput`" ] || [ ! -n "`which ncftpget`" ] #ncftp installiert?
then echo sorry
echo "ncftp not found."
exit
fi
###################################################################
showprofil() #profile anzeigen
{
echo
count=0
echo "Profile:"
echo "_____________"
ls -1 $CONFDIR* | while read line #CONFDIR einlesen
do
count=$[$count +1]
echo -n "[$count]: "
grep "name=" $line | awk -F= '{print $2}'
done
}
addprofil() #profil anlegen
{
if [ ! -e $CONFDIR ]
then
mkdir $CONFDIR && echo Created CONFDIR:$CONFDIR
fi
echo
echo -n "Name (z.b.ale-x)>>"
read name
echo "name=$name" >> $CONFDIR/$name
echo -n "Host (z.b.www.ale-x.com>"
read host
echo "HOST=$host" >> $CONFDIR/$name
echo -n "Username/loginname>>"
read user
echo "USER=$user" >> $CONFDIR/$name
echo -n "Passwort>>"
read pass
echo "PASS=$pass" >> $CONFDIR/$name
}
download() #daten von server laden
{
if ! test -e $CONFDIR/$PROFIL #existiert das profil
then
echo "Profil $PROFIL nicht gefunden"
showprofil
exit
fi
echo "Benutze profil $PROFIL"
USER=`cat $CONFDIR$PROFIL | grep "USER" | awk -F= '{print $2}'` #daten aus dem profil holen
PASS=`cat $CONFDIR$PROFIL | grep "PASS" | awk -F= '{print $2}'`
HOST=`cat $CONFDIR$PROFIL | grep "HOST" | awk -F= '{print $2}'`
USER=`cat $CONFDIR$PROFIL | grep "USER" | awk -F= '{print $2}'`
if [ "$DIR" = "" ]
then
DIR="/"
fi
if test -e $FILE #existiert die datei ?
then
echo "$FILE existiert bereits"
echo "ACHTUNG BEI FALSCHEINGABE KOENNEN FALSCHE DATEIEN GELOESCHT WERDEN->NAME UEBERPRUEFEN!!!!IST $FILE RICHTIG?"
echo -n "Datei löschen? j/n:"
read answer
case $answer in
j) echo "$FILE geloescht";rm -f $FILE;;
n) echo "no";clear && exit 1;;
esac
fi
echo "Starte Download von $FILE"
if ncftpget -u $USER -p $PASS $HOST $LOCALDIR $DIR/$FILE &> /dev/null; then
echo "$FILE erfolgreich von $HOST geladen"
exit 0
else
echo "Download von $FILE fehlgeschlagen"
exit
fi
}
upload() #daten uploaden
{
if ! test -e $CONFDIR/$PROFIL #existiert das profil
then
echo "Profil $PROFIL nicht gefunden"
showprofil
exit
fi
echo "Starte Upload"
echo "Benutze profil $PROFIL"
USER=`cat $CONFDIR$PROFIL | grep "USER" | awk -F= '{print $2}'` #daten aus dem profil holen
PASS=`cat $CONFDIR$PROFIL | grep "PASS" | awk -F= '{print $2}'`
HOST=`cat $CONFDIR$PROFIL | grep "HOST" | awk -F= '{print $2}'`
USER=`cat $CONFDIR$PROFIL | grep "USER" | awk -F= '{print $2}'`
if [ "$DIR" = "" ]
then
DIR="/"
fi
if ! test -e $FILE #existiert die datei ?
then
echo "$FILE existiert nicht"
exit
fi
echo "Starte Upload von $FILE"
if ncftpput -u $USER -p $PASS $HOST $DIR $FILE &> /dev/null; then
echo "$FILE erfolgreich nach $HOST/$DIR geladen"
exit 0
else
echo "Upload von $FILE fehlgeschlagen"
exit 1
fi
}
delprofil() #profile loeschen
{
showprofil
echo "[e]nde"
echo -n ">"
read nr
if [ "$nr" != "q" ] && [ "$nr" != "e" ]
then
rm -f "`ls -1 $CONFDIR/* | head -n $nr | tail -n 1`" && echo "OK" || echo FAILED
fi
sleep 1
}
menu() #hauptmenue
{
clear
echo "ncprof - ncftp profiler v0.1"
echo ""
echo "[z]eige profile"
echo "[n]eues profil anlegen"
echo "[p]rofil loeschen"
echo ""
echo "[e]nde"
echo -n ">"
read line
if [ "$line" = "" ]
then
line=dummy
fi
case $line in
z) showprofil;read moo;;
n) addprofil;;
p) delprofil;;
e) echo "";clear && exit 1;;
q) echo "";clear && exit 1;;
esac
}
if [ "$1" != "" ]
then
if [ "$1" = "-h" ] || [ "$1" = "--help" ] #hilfe
then
echo
echo "ncprof - ncftp profiler"
echo "usage: ncprof #anlegen,loeschen & zeigen der profile"
echo "usage: ncprof [-d] [PROFIL] [FILE] #download ohne verzeichnisangabe ist / default"
echo "usage: ncprof [-d] [PROFIL] [FILE] [DIR] #download aus verzeichnisen ins aktuelle verzeichnis"
echo "usage: ncprof [-p] [PROFIL] [FILE] #upload ohne verzeichnisangabe ist / default"
echo "usage: ncprof [-p] [PROFIL] [FILE] [DIR] #upload aus aktuellen verzeichnis in bestimmtes server verzeichnis"
echo "usage: ncprof [-s/-show] #zeigt alle profile an "
echo "usage: ncprof [-h/--help] #zeigt diese infos "
echo
exit -1
fi
if [ "$1" = "-p" ] #dateien auf den server laden
then
upload
exit
fi
if [ "$1" = "-d" ] #dateien vom server laden
then
download
exit
fi
if [ "$1" = "-show" ] || [ "$1" = "-s" ]
then
showprofil
echo
exit 1
fi
fi
while [ 1 ]
do
clear
menu
done
Zuletzt bearbeitet: