2016-03-18 20 views
0

Merhaba Forumda arama yapıyorum ama bunu doğru göremiyorum. Kullanıcıya hangi süreci aradıklarını soran bir komut dosyası oluşturmaya çalışıyorum ve işlem devam ediyorsa 1 ile döndürür.ps ax betiği için okuma değişkenleri

Bu çalışır:

#!/bin/sh 
echo -e "please enter process name: \c" 
read input_variable 
if ps ax | grep -v grep | grep $varname > /dev/null 
then 
echo "$SERVICE service running, everything is fine" 
else 
echo "$SERVICE is not running" 
fi 

cevap

1

Kullanım pgrep süreçlere aramak için: gibi bir şey için

echo -e "please enter process name: \c" 
read word 

:

#!/bin/bash 
SERVICE='httpd' 
if ps ax | grep -v grep | grep $SERVICE > /dev/null 
then 
echo "$SERVICE service running, everything is fine" 
else 
echo "$SERVICE is not running" 
fi 

Ben komut dosyasına eklemek istiyorum

read process_name 
if pgrep "${process_name}" >/dev/null 2>&1 ; then 
    "echo ${process_name} found" 
else 
    "echo ${process_name} not found" 
fi 
+0

Cool teşekkürler hat 5 ve 7 üzerinde "" dışarı çıkmak için var – nycjay01