Jump to content

Recommended Posts

 

:wtf:

:confused:

:'(

I am attempting to find the value of a variable in a created array.

 

as you can see from the script below. I am identifying any "non system" users by looking at the passwd file and what I want to do is take the userID from passwd, compare it to my known list of system users. I do not want a print out of system users, I just want users that have been created after the fact.

 

The problem is, the if statement is not working and I am getting a print out of all my users, including the ones I do not want to see

 

awk 'BEGIN {
FS=":";
a[1] = "adm";
a[2] = "apache";
a[3] = "bin";
a[4] = "daemon";
a[5] = "ftp";
a[6] = "games";
a[7] = "gopher";
a[8] = "halt";
a[9] = "lp";
a[10] = "mail";
a[11] = "mysql";
a[12] = "named";
a[13] = "news";
a[14] = "nobody";
a[15] = "ntp";
a[16] = "operator";
a[17] = "pcap";
a[18] = "postfix";
a[19] = "radvd";
a[20] = "root";
a[21] = "rpc";
a[22] = "rpm";
a[23] = "shutdown";
a[24] = "sshd";
a[25] = "sync";
a[26] = "syscheck";
a[27] = "testuser";
a[28] = "tomcat4";
a[29] = "uucp";
a[30] = "vcsa";

while ( getline < "/etc/passwd" ) { 
  if ($1 in a){}
  else {print $1}
}
}' 

Link to comment
https://forums.phpfreaks.com/topic/226700-awk-find-variable-value-in-array/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.