Local User Account Info Linux

I am attempting to create an analysis to show me the local user information. Using a BigFix Action Script I have the following:
delete __appendfile
delete run.sh
appendfile “cut -f 1 -d: /etc/passwd | xargs -n 1 -I {} bash -c " echo -e ‘\n{}’ ; chage -l {}”" > /var/opt/BESClient/local.txt
copy __appendfile run.sh
wait sh run.sh

This keeps failing. Originally I didn’t have quotes around the entire cut line but added them and it still fails.

Is there another, more efficient method, to obtain local user information? The end result is to use the Reporting to extract the user information from each machine to monitor user creation and deletion along with just knowing what local accounts are present and password information, expiration and settings.

I think it is the Curly Braces. You may need to escape them:

appendfile “cut -f 1 -d: /etc/passwd | xargs -n 1 -I {{} bash -c " echo -e ‘\n{{}’ ; chage -l {{}”" > /var/opt/BESClient/local.txt

Well that allowed it to run but the /var/opt/BESClient/local.txt file is blank. So it doesn’t appear my command actually executed.

what’s in the besclient logs. It might be tripping some where. Does the “run.sh” has correct syntax of the command?

I added a few more lines to my Action Script -
delete __appendfile
delete run.sh
appendfile “/bin/cat /etc/passwd” > /var/opt/BESClient/passwd.txt
appendfile “”/usr/bin/awk -F":" ‘{print “Login:” $1 “\tName:” $5 “\tHome:” $6}’ /etc/passwd" > /var/opt/BESClient/local_users.txt
appendfile “compgen -g” > /var/opt/BESClient/groups.txt
appendfile “”/usr/bin/getent passwd | awk -F ‘:’ {‘print $1’} | xargs -I {} groups {} | sed ‘s/ : /:/g’ | tr ’ ’ ‘,’" > /var/opt/BESClient/group_membership.txt
appendfile "/usr/bin/getent passwd {1000…60000} > /var/opt/BESClient/local_users.txt
copy __appendfile run.sh
wait sh run.sh

Here is what the log is showing -
At 09:37:15 -0400 - mailboxsite (http://temserver:52311/cgi-bin/bfgather.exe/mailboxsite16146671)
Relevant - [SMG-Linux] Local Account and Group Info (fixlet:456129)
At 09:37:16 -0400 -
ActionLogMessage: (action:456129) Action signature verified for Execution
ActionLogMessage: (action:456129) starting action
At 09:37:16 -0400 - actionsite (http://temserver:52311/cgi-bin/bfgather.exe/actionsite)
Command succeeded delete No ‘/var/opt/BESClient/__BESData/opsite38/__appendfile’ exists to delete, no failure reported (action:456129)
Command succeeded delete No ‘/var/opt/BESClient/__BESData/opsite38/run.sh’ exists to delete, no failure reported (action:456129)
Command succeeded appendfile “/bin/cat /etc/passwd” > /var/opt/BESClient/passwd.txt (action:456129)
Command succeeded (file created) appendfile “/bin/cat /etc/passwd” > /var/opt/BESClient/passwd.txt (action:456129)
Command succeeded appendfile “/bin/cat /etc/passwd” > /var/opt/BESClient/passwd.txt (action:456129)
Command failed (Relevance substitution failed) appendfile “”/usr/bin/awk -F":" ‘{print “Login:” $1 “\tName:” $5 “\tHome:” $6}’ /etc/passwd" > /var/opt/BESClient/local_users.txt (action:456129)
At 09:37:16 -0400 -
ActionLogMessage: (action:456129) ending action
At 09:37:16 -0400 - mailboxsite (http://temserver:52311/cgi-bin/bfgather.exe/mailboxsite16146671)
Not Relevant - [SMG-Linux] Local Account and Group Info (fixlet:456129)

Command failed (Relevance substitution failed) appendfile “”/usr/bin/awk -F":" ‘{print “Login:” $1 “\tName:” $5 “\tHome:” $6}’ /etc/passwd" > /var/opt/BESClient/local_users.txt (action:456129)

2 quick things -

1 - the forum loves to replace our normal DoubleQuotes with SmartQuotes, but the BigFix Agent thinks SmartQuotes are evil and it hates them. If you use the CODE tag, the forum.

use </> button to avoid " " being converted into “ ” and ' ' being converted into ‘ ’

2 - curly braces { } have special meaning in Action Script. They mean "relevance is inside here - calculate the relevance and use the string result inside. You can escape curly braces by doubling them like this: {{

dos echo {computer name} >> c:\test.txt
will result in 
IBMComputer  in c:\test.txt

dos echo {{computer name} >> c:\test.txt 
will result in 
{computer name} in c:\test.txt

TRY:

appendfile "/usr/bin/getent passwd | awk -F ':' {{'print $1;} | xargs -I {{} groups {{} | sed 's/ : /:/g' | tr ' ' ','" > /var/opt/BESClient/group_membership.txt

you can also look in the appendfile on the endpoint and visually inspect it to make sure it contains what you expect.

1 Like

Dang it! I keep forgetting about that.

Thank brolly33 those tips got me going. Appreciate the assistance and education again. :slight_smile:

Everything is creating the text file except the local_users.txt file. The run.sh on the server all looks correct but when I run it from the server it demonstrates the same behavior. If I copy the line and run it on the command line itself it works. I’m confused.

appendfile /usr/bin/getent passwd | awk -F ':' {{'print "Login:" $1 "\tName:" $5 "\tHome:" $6'} > /var/opt/BESClient/local_users.txt

All the others are working. I am trying to get output similar to this:
Login:root Name:root Home:/root
Login:bin Name:bin Home:/bin
Login:daemon Name:daemon Home:/sbin
Login:adm Name:adm Home:/var/adm
Login:lp Name:lp Home:/var/spool/lpd
Login:sync Name:sync Home:/sbin
Login:shutdown Name:shutdown Home:/sbin
Login:halt Name:halt Home:/sbin
Login:mail Name:mail Home:/var/spool/mail
Login:operator Name:operator Home:/root
Login:games Name:games Home:/usr/games
Login:ftp Name:FTP User Home:/var/ftp
Login:nobody Name:Nobody Home:/
Login:systemd-network Name:systemd Network Management Home:/
Login:dbus Name:System message bus Home:/
Login:polkitd Name:User for polkitd Home:/
Login:postfix Name: Home:/var/spool/postfix
Login:chrony Name: Home:/var/lib/chrony
Login:sshd Name:Privilege-separated SSH Home:/var/empty/sshd
Login:tss Name:Account used by the trousers package to sandbox the tcsd daemon Home:/dev/null
Login:cockpit-ws Name:User for cockpit-ws Home:/
Login:sssd Name:User for sssd Home:/
Login:netdata Name:netdata Home:/var/lib/netdata

Maybe there is a better way to get the Login user, name and home directory.

delete __appendfile
delete run.sh
appendfile #!/bin/bash
appendfile /bin/cat /etc/passwd > /var/opt/BESClient/passwd.txt
appendfile /usr/bin/getent passwd | awk -F ':' {{'print "Login:" $1 "\tName:" $5 "\tHome:" $6'} > /var/opt/BESClient/local_users.txt
appendfile compgen -g > /var/opt/BESClient/groups.txt
appendfile /usr/bin/getent passwd | awk -F ':' {{'print $1'} | xargs -I {{}  groups {{} | sed 's/ : /:/g' | tr ' ' ',' > /var/opt/BESClient/group_membership.txt
appendfile /usr/bin/getent passwd {{1000..60000} > /var/opt/BESClient/local_users.txt
copy __appendfile run.sh
wait sh run.sh

I did get this working now. Syntax who would have thought.

Thanks again!