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 7010667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:01:21+00:00 2026-05-27T22:01:21+00:00

The following code works to get the status value of a if its enabled,

  • 0

The following code works to get the status value of a if its enabled, d if its disabled and n if its not present from a file given below:

# Check whether the service entry exists and whether it is enabled or disabled
# Status value 'a' states that the service is uncommented in /etc/inetd.conf.
# Value 'd' states that the service is commented, and value 'n' specifies
# that the service entry doesnt exist in the configuration file.
status=`awk -v serv=$1 -v proto=$2 -v exist="n" '
        BEGIN {
        format=sprintf("^[\t ]*%s.*%s",serv,proto);
        comformat=sprintf("^[\t ]*#[\t ]*%s.*%s",serv,proto);
        }
        {
        if(match($0,format))
        {
                exist="a";
        }
        else if(match($0,comformat))
        {
                exist="d";
        }
        }
        END {
        printf("%s",exist)
        }' $INETD`

From the following file:

ftp     stream  tcp6    nowait  root    /usr/sbin/ftpd         ftpd
telnet  stream  tcp6    nowait  root    /usr/sbin/telnetd      telnetd -a
shell   stream  tcp6    nowait  root    /usr/sbin/rshd         rshd
#kshell  stream  tcp     nowait  root    /usr/sbin/krshd        krshd
login   stream  tcp6    nowait  root    /usr/sbin/rlogind      rlogind
#klogin  stream  tcp     nowait  root    /usr/sbin/krlogind     krlogind

Note: $1 = column 1 in the file and $2 = column 3 in file.

So my concern is if the above searching using the following format good enough? or is there anyother better regular expression:

 format=sprintf("^[\t ]*%s.*%s",serv,proto);
 comformat=sprintf("^[\t ]*#[\t ]*%s.*%s",serv,proto);
  • 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-05-27T22:01:22+00:00Added an answer on May 27, 2026 at 10:01 pm

    Based on what I have understood of the problem this might work –

    status=$(awk -v serv="$1" -v proto="$2" '
    $1==serv && $3==proto {val="a";exit}
    $1=="#"serv && $3==proto {val="d";exit}
    END{if ((val=="a") || (val=="d")) print val; else print "n"}' $INETD)
    

    Test: Based on passing the values manually and using the below content in file

    [jaypal:~/Temp] cat f1
    ftp     stream  tcp6    nowait  root    /usr/sbin/ftpd         ftpd
    telnet  stream  tcp6    nowait  root    /usr/sbin/telnetd      telnetd -a
    shell   stream  tcp6    nowait  root    /usr/sbin/rshd         rshd
    #kshell  stream  tcp     nowait  root    /usr/sbin/krshd        krshd
    login   stream  tcp6    nowait  root    /usr/sbin/rlogind      rlogind
    #klogin  stream  tcp     nowait  root    /usr/sbin/krlogind     krlogind
    
    [jaypal:~/Temp] awk -v serv="kshell" -v proto="tcp" ' # kshell exists but is commented
    $1==serv && $3==proto {val="a";exit}
    $1=="#"serv && $3==proto {val="d";exit}
    END{if ((val=="a") || (val=="d")) print val; else print "n"}' f1
    d
    [jaypal:~/Temp] awk -v serv="ftp" -v proto="tcp6" ' # tcp6 proto exits
    $1==serv && $3==proto {val="a";exit}
    $1=="#"serv && $3==proto {val="d";exit}
    END{if ((val=="a") || (val=="d")) print val; else print "n"}' f1
    a
    [jaypal:~/Temp] awk -v serv="ftp" -v proto="tcp" ' # tcp proto does not exist
    $1==serv && $3==proto {val="a";exit}
    $1=="#"serv && $3==proto {val="d";exit}
    END{if ((val=="a") || (val=="d")) print val; else print "n"}' f1
    n
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following ToolTip code works in WPF . I'm trying to get it to
I have trouble to get gluLookAt working. I have the following code which works
Doing an ajax get request works as expected using the following code: $.ajax({ type:
I am trying to get the following code to work: if (isset($_POST['file'])){ if(file_exists($_POST['file'])){ echo
I have following code that does not work: I never get to goToFoodDetail .
The following code works as expected on CentOS and Ubuntu O/s but not on
When running the following code I get no output but I cannot work out
I have the following code, but I can't get it to work. As soon
I'm trying to get HTML5's audio tag to work in Chrome. The following code
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,

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.