Traitement d'un ensemble de fichier sar : Automatisation

## Introduction
Les données sont les suivantes :
un ensemble de fichier tgz ayant la structure de nom suivante :
pvvvgslwls200-sa.tgz où 

* pvvvgslwls200 est le nom du serveur
* -sa est le type de données
* .tgz la forme de compression.

On doit pour chaque machine produire un document htm output de l'execution ipython notebook du scripts **analysesar.ipynb**

## Installation ipython
Le site suivant décrit les étapes de l'installation [ipython.org](http://ipython.org/install.html)

Pour ubuntu :
> sudo apt-get install ipython-notebook python-matplotlib python-scipy 
  \python-pandas python-sympy python-nose

## installation ipnbdoc.py
Un developpeur de pandas a créé un script python permettant d'éxécuter en CLI un fichier notebook
[davidshinn](https://gist.github.com/davidshinn)

Il suffit de le mettre dans un répertoire de votre machine .... /usr/local/bin par exemple.
L'important est que lors du traitement vous trouviez ce fichier soit dans votre path soit en précisant sa position.

## Description du traitement.
### L'extraction
1. extraction manuel
2. Extraction automatique
3. Copie du fichier analysesar.ipynb
### le script 
> !/bin/bash
\#
\# Extraction des fichiers sar dans un répertoire ayant le nom de machine.
\#
\#-----------------------------------------------------------------------
\# Step 1 : creation d'un répertoire et extraction des fichiers 
\# -----------------------------------------------------------------------
files='ls *.tgz'
for fic in $files; do
     NomRep=${fic%-*}
     echo  "traitement de $fic - $NomRep "
     mkdir $NomRep
     tar xvf $fic
     mv var/log/sa/sar* $NomRep
     cp ../ipynb/analysesar.ipynb $NomRep
     rm $fic
done
\#  petit bug ....
rm -rf ls
\# reste du au tar xvf
rm -rf var

## Production des résultats
1. Creation du fichier pour les données
2. Convertion en html
3. recopie dans un répertoire commun.

> \#!/bin/bash
\#
\# Traitement des fichiers sar par ipython.
\#
\#-----------------------------------------------------------------------
\# Step 2 : Production des résultats 
\# -----------------------------------------------------------------------
\# 
mkdir .html
for directory in `ls` ; do
   cd ${directory}
   
>  pwd
   ../../scripts/ipnbdoc.py  analysesar.ipynb ${directory}.ipynb
   
>   ipython nbconvert --to html ${directory}.ipynb --stdout >${directory}.html
   cp  ${directory}.html ../.html
   cd ..
done

##Le fichier analysesar.ipynb  

Il n'y a pas en ipython notebook de fichier éditable autrement qu'en lançant **ipython notebook**

> pboizot@dbi-ntbk02:/u01/clients/simpany/ipynb$ ipython notebook
2014-04-11 15:05:43.222 [NotebookApp] Using existing profile dir: u'/home/pboizot/.config/ipython/profile_default'
2014-04-11 15:05:43.226 [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js
2014-04-11 15:05:43.241 [NotebookApp] Serving notebooks from local directory: /u01/clients/simpany/ipynb
2014-04-11 15:05:43.241 [NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
2014-04-11 15:05:43.241 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Les fichiers avec l'extension *ipynb* sont au format json. 

>pboizot@dbi-ntbk02:/u01/clients/simpany/ipynb$ head analysesar.ipynb 
{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {

## Annexes :
### Screenshots 
**Lancement de notebook**
![Fentre ouverte au lancement de ipython notebook ][1]
**Ouverture d'un notebook**
![enter image description here][2]


> Written with [StackEdit](https://stackedit.io/).


  [1]: IPython001.png "IPython Dashboard"
  [2]: IPython002.png "Notebook analysesar"