Bonjour,
Voici un script ksh qui permet de killer des process a partir d'une
chaine de caracteres, typiquement quand j'execute mon script en lui
passant une chaine de caractere, il me recherche via la commande ps
tous les process qui matchent ma chaine de caratere puis me propose
pour chacun d'eux de les suppimer ou pas.
Donc je lance la commande :
root@P5101>/home/root$monscript oracle
oracle43 180448 1 0 14:50:13 - 0:00 ora_j000_mvstst
oracle43 196756 1 0 10:09:09 - 0:00 ora_q000_mvstst
oracle43 245904 1 0 10:08:42 - 0:01 ora_pmon_mvstst
Voulez vous supprimer le processus 180448 ?
or si je lance
root@P5101>/home/root$monscript oracle43
root@P5101>
Il ne fait rien !!! Pourquoi ?
On dirait que l'orsque la chaine de caractere se termine par des
chiffres il ne fonctionne pas !!!!
Si quelqu'un pouvait m'eclairer ?
merci
Voici le script :
#! /bin/ksh
if [ "$1" = "" ]
then
echo "Auteur : Pierre HIRTH, le 5 12 2002"
echo "Usage : " $0 "expression [-a]"
exit
fi
{
ps -ef | grep "[^]]$1" | while read z var z; do
if [ "$2" != "-a" ]
then
read <&3 "CHOIX?Voulez vous supprimer le processus $var ?"
if [[ $CHOIX = [oOyY] ]]
then
echo "kill -9 $var" >> $0.log
kill -9 $var
fi
else
echo "kill -9 $var" >> $0.log
kill -9 $var
fi
done
} 3<&0
grep "[^]]$1", ca retourne les lignes qui contiennent un character autre que "]" suivi de "oracle43", donc ca ne matche pas ici.
Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1" a la place.
Bonjour,
pourquoi pas un ps -fu $1 ! ou un egrep -e "(^|[^]])$1" enfin grep -Ee "(^|[^]])$1" pour les puristes :) encore que egrep existe partout et pas grep -E.
HS : à ce propos, le dernier bug sun que j'ai trouvé concerne getopts qui ne supporte pas -xy, mais -x -y ! ce n'est pas vrai avec /usr/xpg4/bin, mais tous les commandes dans /usr/bin n'existent pas dans /usr/xpg4/bin...
Cordialement,
Cyrille Lefevre. -- mailto:Cyrille.Lefevre-news% supprimer "%nospam% et ".invalid" pour me repondre.
or si je lance
root@P5101>/home/root$monscript oracle43
root@P5101>
Il ne fait rien !!! Pourquoi ?
[...]
ps -ef | grep "[^]]$1" | while read z var z; do
[...]
grep "[^]]$1", ca retourne les lignes qui contiennent un
character autre que "]" suivi de "oracle43", donc ca ne matche
pas ici.
Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1"
a la place.
Bonjour,
pourquoi pas un ps -fu $1 !
ou un egrep -e "(^|[^]])$1"
enfin grep -Ee "(^|[^]])$1" pour les puristes :)
encore que egrep existe partout et pas grep -E.
HS : à ce propos, le dernier bug sun que j'ai trouvé
concerne getopts qui ne supporte pas -xy, mais -x -y !
ce n'est pas vrai avec /usr/xpg4/bin, mais tous les
commandes dans /usr/bin n'existent pas dans /usr/xpg4/bin...
Cordialement,
Cyrille Lefevre.
--
mailto:Cyrille.Lefevre-news%nospam@laposte.net.invalid
supprimer "%nospam% et ".invalid" pour me repondre.
grep "[^]]$1", ca retourne les lignes qui contiennent un character autre que "]" suivi de "oracle43", donc ca ne matche pas ici.
Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1" a la place.
Bonjour,
pourquoi pas un ps -fu $1 ! ou un egrep -e "(^|[^]])$1" enfin grep -Ee "(^|[^]])$1" pour les puristes :) encore que egrep existe partout et pas grep -E.
HS : à ce propos, le dernier bug sun que j'ai trouvé concerne getopts qui ne supporte pas -xy, mais -x -y ! ce n'est pas vrai avec /usr/xpg4/bin, mais tous les commandes dans /usr/bin n'existent pas dans /usr/xpg4/bin...
Cordialement,
Cyrille Lefevre. -- mailto:Cyrille.Lefevre-news% supprimer "%nospam% et ".invalid" pour me repondre.
> or si je lance > /home/root$monscript oracle43 >
> Il ne fait rien !!! Pourquoi ? [...] > ps -ef | grep "[^]]$1" | while read z var z; do
[...]
grep "[^]]$1", ca retourne les lignes qui contiennent un character autre que "]" suivi de "oracle43", donc ca ne matche pas ici.
Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1" a la place.
-- Stéphane
merci Stephane.
le pierre
> pourquoi pas un ps -fu $1 ! ou un egrep -e "(^|[^]])$1" enfin grep -Ee "(^|[^]])$1" pour les puristes :)
Le man n'etant pas assez clair, pouvez vous m'expliquer littéralement (en detaillant chaque parametre des commandes egrep) ce que font chacune de vos trois commande ?
merci
> pourquoi pas un ps -fu $1 !
ou un egrep -e "(^|[^]])$1"
enfin grep -Ee "(^|[^]])$1" pour les puristes :)
Le man n'etant pas assez clair, pouvez vous m'expliquer littéralement
(en detaillant chaque parametre des commandes egrep) ce que font
chacune de vos trois commande ?
> pourquoi pas un ps -fu $1 ! ou un egrep -e "(^|[^]])$1" enfin grep -Ee "(^|[^]])$1" pour les puristes :)
Le man n'etant pas assez clair, pouvez vous m'expliquer littéralement (en detaillant chaque parametre des commandes egrep) ce que font chacune de vos trois commande ?
merci
le pierre
On 12 sep, 09:08, le pierre wrote:
> pourquoi pas un ps -fu $1 ! > ou un egrep -e "(^|[^]])$1" > enfin grep -Ee "(^|[^]])$1" pour les puristes :)
Le man n'etant pas assez clair, pouvez vous m'expliquer littéralement (en detaillant chaque parametre des commandes egrep) ce que font chacune de vos trois commande ?
merci
C'est vrai que le ps -fu $1 est pas mal du tout !!!!
On 12 sep, 09:08, le pierre <p.hi...@gmail.com> wrote:
> pourquoi pas un ps -fu $1 !
> ou un egrep -e "(^|[^]])$1"
> enfin grep -Ee "(^|[^]])$1" pour les puristes :)
Le man n'etant pas assez clair, pouvez vous m'expliquer littéralement
(en detaillant chaque parametre des commandes egrep) ce que font
chacune de vos trois commande ?
merci
C'est vrai que le ps -fu $1 est pas mal du tout !!!!
> pourquoi pas un ps -fu $1 ! > ou un egrep -e "(^|[^]])$1" > enfin grep -Ee "(^|[^]])$1" pour les puristes :)
Le man n'etant pas assez clair, pouvez vous m'expliquer littéralement (en detaillant chaque parametre des commandes egrep) ce que font chacune de vos trois commande ?
merci
C'est vrai que le ps -fu $1 est pas mal du tout !!!!
le pierre
> Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1" a la place.
-- Stéphane
J'ai encore une question -e "^$1" , ca veut dire le caractere vide suivi du contenu de $1 ?
> Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1"
a la place.
--
Stéphane
J'ai encore une question -e "^$1" , ca veut dire le caractere vide
suivi du contenu de $1 ?
> Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1" a la place.
-- Stéphane
J'ai encore une question -e "^$1" , ca veut dire le caractere vide suivi du contenu de $1 ?
Stephane CHAZELAS
2008-09-12, 01:33(-07), le pierre:
Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1" a la place.
[...]
J'ai encore une question -e "^$1" , ca veut dire le caractere vide suivi du contenu de $1 ?
[...]
Voir grep(1) et regex(7) (ou regex(5)):
BRE Expression Anchoring A BRE can be limited to matching strings that begin or end a line; this is called anchoring. The circumflex and dollar sign special characters will be considered BRE anchors in the following contexts:
1. A circumflex ( ^ ) is an anchor when used as the first character of an entire BRE. The implementation may treat circumflex as an anchor when used as the first character of a subexpression. The circumflex will anchor the expression to the beginning of a string; only sequences starting at the first character of a string will be matched by the BRE. For example, the BRE ^ab matches ab in the string abcdef, but fails to match in the string cdefab. A portable BRE must escape a leading circumflex in a subexpression to match a literal circumflex.
-- Stéphane
2008-09-12, 01:33(-07), le pierre:
Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1"
a la place.
[...]
J'ai encore une question -e "^$1" , ca veut dire le caractere vide
suivi du contenu de $1 ?
[...]
Voir grep(1) et regex(7) (ou regex(5)):
BRE Expression Anchoring
A BRE can be limited to matching strings that begin or end a
line; this is called anchoring. The circumflex and dollar
sign special characters will be considered BRE anchors in
the following contexts:
1. A circumflex ( ^ ) is an anchor when used as the first
character of an entire BRE. The implementation may
treat circumflex as an anchor when used as the first
character of a subexpression. The circumflex will
anchor the expression to the beginning of a string;
only sequences starting at the first character of a
string will be matched by the BRE. For example, the
BRE ^ab matches ab in the string abcdef, but fails
to match in the string cdefab. A portable BRE must
escape a leading circumflex in a subexpression to
match a literal circumflex.
Tu peux faire "ps -ef | grep -e "[^]]$1" -e "^$1" a la place.
[...]
J'ai encore une question -e "^$1" , ca veut dire le caractere vide suivi du contenu de $1 ?
[...]
Voir grep(1) et regex(7) (ou regex(5)):
BRE Expression Anchoring A BRE can be limited to matching strings that begin or end a line; this is called anchoring. The circumflex and dollar sign special characters will be considered BRE anchors in the following contexts:
1. A circumflex ( ^ ) is an anchor when used as the first character of an entire BRE. The implementation may treat circumflex as an anchor when used as the first character of a subexpression. The circumflex will anchor the expression to the beginning of a string; only sequences starting at the first character of a string will be matched by the BRE. For example, the BRE ^ab matches ab in the string abcdef, but fails to match in the string cdefab. A portable BRE must escape a leading circumflex in a subexpression to match a literal circumflex.