Lancement d'un script avec argument

Résolu/Fermé
nabil1706 Messages postés 17 Date d'inscription mardi 21 novembre 2006 Statut Membre Dernière intervention 22 décembre 2006 - 12 déc. 2006 à 14:30
nabil1706 Messages postés 17 Date d'inscription mardi 21 novembre 2006 Statut Membre Dernière intervention 22 décembre 2006 - 13 déc. 2006 à 15:51
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

3 réponses

lami20j Messages postés 21331 Date d'inscription jeudi 4 novembre 2004 Statut Modérateur, Contributeur sécurité Dernière intervention 30 octobre 2019 3 567
12 déc. 2006 à 21:22
Salut,

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 0 
Pour l'exécuter fait comme t'a dit mamiemando
2
mamiemando Messages postés 33079 Date d'inscription jeudi 12 mai 2005 Statut Modérateur Dernière intervention 23 avril 2024 7 749
12 déc. 2006 à 20:21
chmod +x Script.sh
./Script.sh Call1

Bonne chance
0
nabil1706 Messages postés 17 Date d'inscription mardi 21 novembre 2006 Statut Membre Dernière intervention 22 décembre 2006 2
13 déc. 2006 à 15:51
Merci,

Il etait deja excecutable
sinon il fallait declarer l'argument au debut...
0