Pular para o conteúdo

Daemon em shell script [RESOLVIDO]

Responder tópico
  • Denunciar
  • Indicar

1. Daemon em shell script [RESOLVIDO]

Enviado em 18/11/2018 - 16:39h

Preciso checar se o processo emerge está rodando e caso verdadeiro então deve montar um diretório na RAM (a montagem está descrita no fstab), tenho isso:


#!/bin/bash

if [ -z $(pgrep emerge) ]
then
while true
do
sleep 1
mount tmpfs
done
else
umount tmpfs
fi


Mas quando rodo o resultado é esse:


pgrep emerge
# Nenhuma saída, processo não está rodando

findmnt /var/tmp/portage
TARGET SOURCE FSTYPE OPTIONS
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250


Ele monta a pasta várias vezes mesmo que o emerge não esteja rodando.

Responder tópico

2. Re: Daemon em shell script [RESOLVIDO]

Melhor resposta

Enviado em 18/11/2018 - 19:14h

pylm escreveu:

Preciso checar se o processo emerge está rodando e caso verdadeiro então deve montar um diretório na RAM (a montagem está descrita no fstab), tenho isso:


#!/bin/bash

if [ -z $(pgrep emerge) ];then
while true; do
sleep 1
mount tmpfs
done
else
umount tmpfs
fi


Mas quando rodo o resultado é esse:


pgrep emerge
# Nenhuma saída, processo não está rodando

findmnt /var/tmp/portage
TARGET SOURCE FSTYPE OPTIONS
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250
/var/tmp/portage tmpfs tmpfs rw,noatime,size=2097152k,mode=775,uid=250,gid=250


Ele monta a pasta várias vezes mesmo que o emerge não esteja rodando.
Boa noite!
Sim, conforme seus comandos:
if [ -z $(pgrep emerge) ]; #Se for vazio.... entra no laço infinito . . .
while true; do
sleep 1
mount tmpfs
done

Segue sugestão:
#!/bin/bash
programa="emerge"

clear
while :;do
printf " %()T\n"
sleep 2.5;
if pgrep "$programa" > /dev/null;then
echo " "$programa" Está rodando.\n Verificar se tmpfs está montado...\n Se NãO, Montar tmpfs";
echo -e " #COMANDO PARA MONTAR TMPFS#\n";
#Para ENCERRAR o laço, descomente a linha abaixo
# break;
else
echo -e " "$programa" Não esta rodando.\n Verificar se tmpfs está montado...Se sim, desmonta";
echo -e " #COMANDO PARA DESMONTAR TMPFS#\n";
fi
done

Marcelo Oliver

3. Re: Daemon em shell script [RESOLVIDO]

Enviado em 18/11/2018 - 19:20h

Tenta assim:

#!/bin/bash
PROCESSO=emerge
while true; do
# numero de cópias do processo rodando
OCORRENCIAS=`pgrep -c $PROCESSO`
if [ $OCORRENCIAS -eq 0 ]; then
# Igual a zero: O processo NÃO está rodando
umount tmpfs
else
# Diferente de zero: O processo está rodando
mount tmpfs
fi
# Aguarda o intervalo especificado e executa novamente o script
sleep 10
done

4. Re: Daemon em shell script [RESOLVIDO]

Enviado em 18/11/2018 - 19:27h

Marcelo sempre com as melhores soluções, valeu irmão.


5. Re: Daemon em shell script [RESOLVIDO]

Enviado em 18/11/2018 - 20:20h

pylm escreveu:

Marcelo sempre com as melhores soluções, valeu irmão.
Valeu, pylm .
Precisando, estou por aqui...
Abç.:
Marcelo Oliver

Responder tópico

Responder tópico

Entre na sua conta para responder.

Fazer login para responder