Lancement d'un script avec argument
Résolu
nabil1706
Messages postés
17
Date d'inscription
Statut
Membre
Dernière intervention
-
nabil1706 Messages postés 17 Date d'inscription Statut Membre Dernière intervention -
nabil1706 Messages postés 17 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
voila mon script :
#!/bin/sh
A=$(date '+%m'"_20"'%y')
if [ -z "$n" ] ; then
echo "Vous n'avez pas passe parametre"
else
case $n in
Call) tail -1 StatProfileDailyCall_$A.csv |awk -F"," '{print $2}' > test1.txt
;;
Call1) tail -1 StatProfileDailyCall_$A.csv |awk -F"," '{print $3}' > test1.txt
;;
Call2) tail -1 StatProfileDailyCall_$A.csv |awk -F"," '{print $5}' > test1.txt
;;
Duration1) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $2}' > test1.txt
;;
Duration2) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $3}' > test1.txt
;;
Duration3) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $6}' > test1.txt
;;
Duration4) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $7}' > test1.txt
;;
Mbox) tail -1 StatProfileDailyMbox_$A.csv |awk -F"," '{print $2}' > test1.txt
;;
Msg) tail -1 StatProfileDailyMsg_$A.csv |awk -F"," '{print $2}' > test1.txt
;;
*) exit
;;
esac
fi
cat test1.txt
exit 0
Les fichiers stats sont de ce type :
Date,MboxCount,ActiveMbox,
01/12/2006,78182,0,
02/12/2006,78795,0,
03/12/2006,79311,0,
04/12/2006,79989,0,
05/12/2006,80659,0,
06/12/2006,81386,0,
07/12/2006,82129,0,
08/12/2006,82831,0,
09/12/2006,83302,0,
10/12/2006,83739,0,
Je recupere les champs qui m'interessent dans le script (la derniere ligne et une ou plusieurs colonnes non vides) et
je n'arrive pas a lancer le script :
Script. sh Call1
Merci de votre aide
voila mon script :
#!/bin/sh
A=$(date '+%m'"_20"'%y')
if [ -z "$n" ] ; then
echo "Vous n'avez pas passe parametre"
else
case $n in
Call) tail -1 StatProfileDailyCall_$A.csv |awk -F"," '{print $2}' > test1.txt
;;
Call1) tail -1 StatProfileDailyCall_$A.csv |awk -F"," '{print $3}' > test1.txt
;;
Call2) tail -1 StatProfileDailyCall_$A.csv |awk -F"," '{print $5}' > test1.txt
;;
Duration1) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $2}' > test1.txt
;;
Duration2) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $3}' > test1.txt
;;
Duration3) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $6}' > test1.txt
;;
Duration4) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $7}' > test1.txt
;;
Mbox) tail -1 StatProfileDailyMbox_$A.csv |awk -F"," '{print $2}' > test1.txt
;;
Msg) tail -1 StatProfileDailyMsg_$A.csv |awk -F"," '{print $2}' > test1.txt
;;
*) exit
;;
esac
fi
cat test1.txt
exit 0
Les fichiers stats sont de ce type :
Date,MboxCount,ActiveMbox,
01/12/2006,78182,0,
02/12/2006,78795,0,
03/12/2006,79311,0,
04/12/2006,79989,0,
05/12/2006,80659,0,
06/12/2006,81386,0,
07/12/2006,82129,0,
08/12/2006,82831,0,
09/12/2006,83302,0,
10/12/2006,83739,0,
Je recupere les champs qui m'interessent dans le script (la derniere ligne et une ou plusieurs colonnes non vides) et
je n'arrive pas a lancer le script :
Script. sh Call1
Merci de votre aide
A voir également:
- Lancement d'un script avec argument
- Script vidéo youtube - Guide
- Mas script - Accueil - Windows
- Ghost script - Télécharger - Polices de caractères
- Script cmd - Guide
- Python est introuvable. exúcutez sans argument pour procúder ó l ✓ - Forum Python
3 réponses
Salut,
il faut utiliser $1 et pas $n
$1 --> argument 1
il faut utiliser $1 et pas $n
$1 --> argument 1
#!/bin/sh A=$(date '+%m'"_20"'%y') if [ -z $1 ] ; then echo "Vous n'avez pas passe parametre" else case $1 in Call) tail -1 StatProfileDailyCall_$A.csv |awk -F"," '{print $2}' > test1.txt ;; Call1) tail -1 StatProfileDailyCall_$A.csv |awk -F"," '{print $3}' > test1.txt ;; Call2) tail -1 StatProfileDailyCall_$A.csv |awk -F"," '{print $5}' > test1.txt ;; Duration1) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $2}' > test1.txt ;; Duration2) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $3}' > test1.txt ;; Duration3) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $6}' > test1.txt ;; Duration4) tail -1 StatProfileDailyDuration_$A.csv |awk -F"," '{print $7}' > test1.txt ;; Mbox) tail -1 StatProfileDailyMbox_$A.csv |awk -F"," '{print $2}' > test1.txt ;; Msg) tail -1 StatProfileDailyMsg_$A.csv |awk -F"," '{print $2}' > test1.txt ;; *) echo "Parametre inexistant" exit ;; esac fi cat test1.txt exit 0Pour l'exécuter fait comme t'a dit mamiemando