2016-03-18 2 views
0

こんにちは私はフォーラムで検索してきましたが、私はこの権利を得ることはできません。私は、プロセスが実行されている場合、どのプロセスが検索してから1を返したかをユーザーに尋ねるスクリプトを作成しようとしています。変数をps axスクリプトに読み込む

これは動作します:

#!/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 

答えて

1

使用pgrepは、プロセスを検索する:ような何かのために

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 

私はスクリプトにこれを追加したい

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

5行目と7行目の " – nycjay01

関連する問題