Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 90bbb6e209 | |||
| 765c4c03d0 | |||
| 10bf6e47f7 | |||
| 0ba83cd768 |
@@ -1,5 +1,12 @@
|
|||||||
## Fonctions
|
## Fonctions
|
||||||
|
|
||||||
|
### Exercice 1
|
||||||
|
|
||||||
|
le script eval.sh présente des redondances de code qui le rende difficile à maintenir.
|
||||||
|
|
||||||
|
Dans l'idéal il faudra factoriser en créeant 2 fonctions
|
||||||
|
|
||||||
|
### Exercice 2
|
||||||
|
|
||||||
Définir dans le fichier myfunctions.sh une fonction "myerror" prenant 2 arguments en entrée: un code et un message.
|
Définir dans le fichier myfunctions.sh une fonction "myerror" prenant 2 arguments en entrée: un code et un message.
|
||||||
|
|
||||||
|
|||||||
30
eval.sh
Normal file
30
eval.sh
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
function fileMTime {
|
||||||
|
if [ ! -f $1 ] ; then echo -ne "0;" ; return 0 ; fi
|
||||||
|
stat --printf "%y;" $1
|
||||||
|
}
|
||||||
|
|
||||||
|
function fileMustContains {
|
||||||
|
file=$1
|
||||||
|
shift
|
||||||
|
string=$@
|
||||||
|
if [ ! -f $file ] ; then echo -ne "0;" ; return 0 ;fi
|
||||||
|
if ( grep -i -qE "${string}" $file ) ;
|
||||||
|
then echo -ne "1;"
|
||||||
|
else
|
||||||
|
echo -ne "0;"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
host=$1
|
||||||
|
root=${host}/rootfs
|
||||||
|
host=$(basename $host)
|
||||||
|
hostname=$(grep HOSTNAME ${root}/etc/sysconfig/network 2>/dev/null| cut -f2 -d=)
|
||||||
|
fileMTime ${root}/root/.bash_history
|
||||||
|
fileMTime ${root}/home/formation/.bash_history
|
||||||
|
fileMTime ${root}/etc/motd
|
||||||
|
fileMustContains ${root}/etc/profile.d/zalias.sh "today"
|
||||||
|
fileMustContains ${root}/etc/profile.d/zconf.sh "PS1"
|
||||||
|
fileMustContains ${root}/etc/profile.d/zconf.sh "HISTSIZE"
|
||||||
7
myfunctions.sh
Normal file
7
myfunctions.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
function myerror {
|
||||||
|
code=$1
|
||||||
|
shift
|
||||||
|
msg="$*"
|
||||||
|
echo $msg
|
||||||
|
exit $code
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user