maniu@securebrain.com:~/script# vi glpi



# catena di script che ho scritto per popolare massivamente un database GLPI
# presuppone l'esistenza di una lista 
# name - serial - mac - model - serial monitor - model monitor


# cat princ
# redirigere l'output su un file (nel mio esempio >> esegui)
# crea uno script che lancia scriptm con i paramentri di lista
IFS=$'\n'
for i in `cat lista |awk -F "; " '{ printf "\"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", $1, $2, $3, $4, $5, $6 }' | tr -d ";"`;
do
echo "./scriptm $i"
done

------------------------------------------------------------------------------------

# esempio di output
# cat esegui
./scriptm "host1" "1pggp2f" "0U18867910c7" "DELL OPTIPLEX 740" "" ""
./scriptm "host2" "7DTKP2f" "00688B55655E" "DELL OPTIPLEX 740" "" ""
./scriptm "host3" "19yxpyf" "00188b88Ufae" "DELL OPTIPLEX 320" "302Uapl69664" "benq 17"
./scriptm "host4" "2rlwpgf" "0U686bU86dd0" "DELL OPTIPLEX 320" "302w3gn3w215" "lg l1915s"
....

------------------------------------------------------------------------------------

#cat scriptm

#network= 5 milano, 4 cinisello
#location= 1 milano, 4 cinisello
#type= 3 laptop, 4 desktop
# id presi dalle tabelle glpi.*

# name - serial - mac - model - serial monitor - model monitor
# $1, $2, $3, $4, $5, $6
# calcolo in base alla naming conv. delle macchine
case $1 in
                02*)
                location=4
                network=4
                ;;
                01*)
                location=1
                network=5
                ;;
                *)
                location=""
                network=""
                ;;
esac
case $4 in
        "ibm 8198")
        model=43
        ;;
        "ibm 8309")
        model=44
        ;;
        "ibm 8313")
        model=45
        ;;
        "ibm 8191")
        model=42
        ;;
        "ibm 8132")
        model=41
        ;;
        "ibm 8084")
        model=40
        ;;
        "DELL OPTIPLEX 320")
        model=37
        ;;
        "DELL OPTIPLEX 740")
        model=38
        ;;
        "MAXDATA")
        model=39
        ;;
        *)
        model=""
        ;;
esac

case $6 in
        "DELL 17")
        modelm=12
        ;;
        "DELL 19")
        modelm=13
        ;;
        "benq 17")
        modelm=14
        ;;
        "lg flatron 15")
        modelm=15
        ;;
        "lg flatron 17")
        modelm=16
        ;;
        "lg flatron 19")
        modelm=17
        ;;
        "lg l1915s")
        modelm=18
        ;;
        *)
        modelm=""
        ;;
esac
# $1, $2, $3, $4, $5, $6

# insert computer
echo "INSERT INTO glpi_computers  VALUES  ('','$1','$2','$3','','','14','','2007-03-07 16:19:35','1','0','0','0','$location','1','$network','$model','4','0','DesktopClient','0','N','NULL','0','0','5');"
if  [ ! -z $5 ] || [ ! -z $6 ];
then
# insert monitor
echo "INSERT INTO glpi_monitors  VALUES ('','$6', '2007-03-07 17:11:27', '','', ' 0', '','$5','','0', '0', '0','0', '0', '0','$location','0','$modelm','0 ', '0', 'N','0', 'ClientMonitor','NULL','14', '5');"


# insert connection
echo  "insert  into glpi_connect_wire (end1,end2) SELECT glpi_monitors.id,glpi_computers.id FROM glpi_monitors,glpi_computers WHERE  glpi_monitors.serial='$5' and glpi_computers.serial='$2' ;"
fi



------------------------------------------------------------------------------------

infine settare il type = 4 per la connessione fra pc e monitor

update glpi_connect_wire set type='4';




:q!