Article View: es.comp.os.linux.programacion
Article #8549Re: Programacion Script
From: zd
Date: Wed, 30 Oct 2002 22:41
Date: Wed, 30 Oct 2002 22:41
78 lines
2899 bytes
2899 bytes
Sand Man <sand_man@terra.es> escribi�:
> Hola,
>
> Alguien me podria decir como pudeo programar un scrip que:
>
> 1� Identifique el PID de un proceso del cual se conoce el nombre.
> 2� Matar ese proceso por su numero de PID.
Aunque me parece extra�a esa petici�n, aqu� va eso:
---- C�DIGO ----
#!/bin/bash
#
# Autor: Zeles Deree (zeldere)
# Correo: zeldere@yahoo.es
#
MAL_ARG=65
MAL_SEL=66
NO_PERM=67
if [ "${1}" = "" ]; then
echo
echo "Tienes que especificar un proceso."
exit $MAL_ARG
else
CORRE="$(echo $(ps -Ao comm | grep ${1}))"
if [ "$CORRE" = "" ]; then
echo
echo "El proceso no est� ejecut�ndose. Saliendo..."
exit 0
else
echo
PROCESO="$(ps -Ao comm | grep "${1}")"
PID=($(ps -Ao pid,comm | grep "${1}"))
echo -n "�Desea matar el proceso \""$PROCESO"\" cuyo identificador \
es, \""${PID[0]}"\"?; [S/N]: "
read SEL
case "$SEL" in
[s,S])
if kill -9 "$PID" &>/dev/null ; then
echo
echo "Hecho. Saliendo..."
exit 0
else
echo
echo "Operaci�n no permitida. Saliendo..."
exit $NO_PERM
fi
;;
[n,N])
echo
echo "Saliendo..."
exit 0
;;
*)
echo
echo "Opci�n incorrecta. Saliendo..."
exit $MAL_SEL
;;
esac
fi
fi
exit 0
---- C�DIGO ----
Un saludo.
--
Zeles Deree (zeldere) .zd
* Correo: zeldere@yahoo.es
* GNU/Linux - LFS 3.1
Technical Details
Message-ID:
<appn6a$bh9$2@titan.bt.es>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.icl.net!newsfeed.fjserv.net!news.netkonect.net!btnet-peer0!btnet-peer!btnet!newsfeed.bt.es!news.bt.es!not-for-mailReferences:
<appg5h$ch5$1@nsnmrro2-gest.nuria.telefonica-data.net>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,28cffd7948076415 X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2002-10-30 14:57:45 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.icl.net!newsfeed.fjserv.net!news.netkonect.net!btnet-peer0!btnet-peer!btnet!newsfeed.bt.es!news.bt.es!not-for-mail From: zd <zeldere|_nospam|@yahoo.es> Newsgroups: es.comp.os.linux.programacion Subject: Re: Programacion Script Supersedes: <appn2j$bh9$1@titan.bt.es> Date: 30 Oct 2002 22:41:14 GMT Organization: BT Tel. Netnews service (readers) Lines: 78 Message-ID: <appn6a$bh9$2@titan.bt.es> References: <appg5h$ch5$1@nsnmrro2-gest.nuria.telefonica-data.net> NNTP-Posting-Host: cable223a208.usuarios.retecal.es Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Trace: titan.bt.es 1036017674 11817 212.183.223.208 (30 Oct 2002 22:41:14 GMT) X-Complaints-To: abuse@bt.es NNTP-Posting-Date: 30 Oct 2002 22:41:14 GMT User-Agent: slrn/0.9.7.3 (Linux)