Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:10:13+00:00 2026-06-01T20:10:13+00:00

I am trying to write a shell script that looks if a particular program

  • 0

I am trying to write a shell script that looks if a particular program is running and if it is not, it restarts the service.
Also it checks if the interface is in promiscuous mode. If it is not, it puts it in that mode.

To check if prog xyz is running, I can do the following on commandline

ps -ef | grep -v grep | grep xyz | wc -l

If it returns 0, progrma is not running, else it is running

Similarly to check if the interface is in promisc mode I can do the following on the command line

ip link show eth0 | grep -i promisc | wc -l

Again if return is 1, interface is in promisc mode.

The problem comes when I try to bundle it all in a shell script.

#!/bin/bash
SERVICE="daemonlogger"
x=$(ps -ef|grep -v grep|grep $SERVICE|wc -l)
if [ "$x" -eq 1 ]; then
 run=0
 else
 run=1
fi
IF_NAME="eth0"
y=$(ip link show $IF_NAME|grep -i promisc|wc -l)
if [ "$y" -eq 1 ]; then
 :
 else
 ifconfig $IF_NAME promisc up
fi
if [ "$run" -eq 1 ]; then
 service $SERVICE restart > /dev/NULL 2>&1
fi
echo $run

The output of commands if run from the command line is

[root@dheerajpc Desktop]# ps -ef | grep -v grep | grep daemonlogger | wc -l
0
[root@dheerajpc Desktop]# ip link show eth0 | grep -i promisc | wc -l
0

Here’s the output of running it in debug mode

[root@dheerajpc Desktop]# bash -x check_daemonlogger 
+ SERVICE=daemonlogger
++ ps -ef
++ wc -l
++ grep daemonlogger
++ grep -v grep
+ x=2
+ '[' 2 -eq 1 ']'
+ run=1
+ IF_NAME=eth0
++ grep -i promisc
++ ip link show eth0
++ wc -l
+ y=0
+ '[' 0 -eq 1 ']'
+ ifconfig eth0 promisc up
+ '[' 1 -eq 1 ']'
+ service daemonlogger restart
+ echo 1
1

As can be seen the output of first command is not what is expected, while the output of second command is correct.

What am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:10:16+00:00Added an answer on June 1, 2026 at 8:10 pm

    Hint: What’s your script called?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a shell script that will make several targets into several
I am trying to write a wrapper shell script that caches information every time
I am trying to write a simple shell-script that prints out the first parameter
I'm trying to write a VBScript (.vbs) script that uses the WScript.Shell Run() method,
I am trying to write a bourne-shell script that takes a directory as a
I'm trying to write a shell script that, when run, will set some environment
I'm trying to write a shell script that does a search and replace inside
hi I am trying to write a bourne-shell script that takes a name as
I am trying to write a bourne-shell script that takes a string as a
I am trying to write a bash shell script that consumes a high amount

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.