Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Script " Kill "

19 réponses
Avatar
Michael
Bonjour,

Je cherche à automatiser les actions suivantes avec un script shell :

- lancer une connexion ssh
- ps -ax | grep "Remote Desktop.app" ( pour Apple remote desktop )
- kill PID " Remote Desktop.app "

Comment récupérer le PID à tuer dans le script ?

Merci.

10 réponses

1 2
Avatar
olivier.marti
Michael wrote:

Bonjour,

Je cherche à automatiser les actions suivantes avec un script shell :

- lancer une connexion ssh
- ps -ax | grep "Remote Desktop.app" ( pour Apple remote desktop )
- kill PID " Remote Desktop.app "

Comment récupérer le PID à tuer dans le script ?

Merci.




en bash :

PID=$( ps -ax | grep Finder | grep -v grep | awk '{print $1}' )


Mais il y doit avoir mieux :

killall Remote Desktop

Olivier
Avatar
Michael
PID=$( ps -ax | grep Finder | grep -v grep | awk '{print $1}' )



Voilà, c'est cette commande awk qu'il me fallait : man awk :-)

Ceci étant, si je fais ensuite un echo $PID j'ai ( par exemple ) :
262 337

alors que c'est un kill 3369 qui tue Remote … ( kill 262337, no such process )


Mais il y doit avoir mieux :

killall Remote Desktop



Ne marche pas :

No matching processes belonging to you were found

alors que Remote est bien lancé sur le micro distant.
Avatar
Éric Lévénez
Le 11/09/11 11:06, Michael a écrit :
PID=$( ps -ax | grep Finder | grep -v grep | awk '{print $1}' )



Voilà, c'est cette commande awk qu'il me fallait : man awk :-)



Cette commande traîne sur Internet depuis longtemps. Le grep -v grep est
juste parce que l'option -c a été oubliée dans le ps. Bref, pour faire
la même chose :

ps -axc | grep -w Finder | awk '{print $1}'

--
Éric Lévénez -- <http://www.levenez.com/&gt;
Unix is not only an OS, it's a way of life.
Avatar
patpro ~ patrick proniewski
In article <4e6c83ff$0$14975$,
Éric Lévénez wrote:

Le 11/09/11 11:06, Michael a écrit :
>> PID=$( ps -ax | grep Finder | grep -v grep | awk '{print $1}' )
>
> Voilà, c'est cette commande awk qu'il me fallait : man awk :-)

Cette commande traîne sur Internet depuis longtemps. Le grep -v grep est
juste parce que l'option -c a été oubliée dans le ps. Bref, pour faire
la même chose :

ps -axc | grep -w Finder | awk '{print $1}'



en même temps...

ps -axc | awk '/Finder/ {print $1}'

mais bon, pourquoi le Finder alors qu'on cherche Remote Desktop ? :)

patpro

--
A vendre : KVM IP 16 ports APC
http://patpro.net/blog/index.php/2008/01/12/133
Avatar
Éric Lévénez
Le 11/09/11 11:57, patpro ~ patrick proniewski a écrit :
In article<4e6c83ff$0$14975$,
Éric Lévénez wrote:

ps -axc | grep -w Finder | awk '{print $1}'



en même temps...

ps -axc | awk '/Finder/ {print $1}'



Oui, effectivement. Mais de toute façon le killall est préférable dans
tous les cas.

mais bon, pourquoi le Finder alors qu'on cherche Remote Desktop ? :)



Ah, ça c'est une autre histoire. :-)

--
Éric Lévénez -- <http://www.levenez.com/&gt;
Unix is not only an OS, it's a way of life.
Avatar
xavier
patpro ~ patrick proniewski wrote:

mais bon, pourquoi le Finder alors qu'on cherche Remote Desktop ? :)



Faudrait déja voir la sortie de
ps -ax | grep 'Remote Desktop'
oui, sans le "-c" chez l'OP, pour essayer de comprendre pourquoi kill ne
marche pas.

--
XAv
In your pomp and all your glory you're a poorer man than me,
as you lick the boots of death born out of fear.
(Jethro Tull)
Avatar
Michael
On 2011-09-11 10:16:39 +0000, Xavier said:

patpro ~ patrick proniewski wrote:

mais bon, pourquoi le Finder alors qu'on cherche Remote Desktop ? :)



Faudrait déja voir la sortie de
ps -ax | grep 'Remote Desktop'
oui, sans le "-c" chez l'OP, pour essayer de comprendre pourquoi kill ne
marche pas.



MacBookPro13:~ michael$ ps -ax | grep "Remote Desktop"
3369 ?? 0:03.68 /Applications/Remote
Desktop.app/Contents/MacOS/Remote Desktop -psn_0_9193668
3488 ttys000 0:00.00 grep Remote Desktop
Avatar
Michael

MacBookPro13:~ michael$ ps -ax | grep "Remote Desktop"
3369 ?? 0:03.68 /Applications/Remote
Desktop.app/Contents/MacOS/Remote Desktop -psn_0_9193668
3488 ttys000 0:00.00 grep Remote Desktop



J'oubliais : Mac OS X 10.7.1 parfaitement à jour ( y compris ARD )
Avatar
xavier
Michael wrote:

MacBookPro13:~ michael$ ps -ax | grep "Remote Desktop"
3369 ?? 0:03.68 /Applications/Remote
Desktop.app/Contents/MacOS/Remote Desktop -psn_0_9193668
3488 ttys000 0:00.00 grep Remote Desktop



Donc awk'{print $1}' va bien te renvoyer le pid correct. Et "kill 3369"
continue à te renvoyer une erreur ?

--
XAv
In your pomp and all your glory you're a poorer man than me,
as you lick the boots of death born out of fear.
(Jethro Tull)
Avatar
Michael
Donc awk'{print $1}' va bien te renvoyer le pid correct. Et "kill 3369"
continue à te renvoyer une erreur ?



Non, awk ne me renvoit pas le bon PID ( voir un de mes messages précédents ).

Par contre, le kill 3369 " manuel " est OK.
1 2