Skip to content

Instantly share code, notes, and snippets.

@mirekfranc
Created April 24, 2015 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirekfranc/30fe3817183347c854f0 to your computer and use it in GitHub Desktop.
Save mirekfranc/30fe3817183347c854f0 to your computer and use it in GitHub Desktop.
Which user uses which shell on unix in C++11
#include <iostream>
#include <map>
#include <string>
#include <sys/types.h>
#include <pwd.h>
int
main (int argc, char *argv[])
{
std::map<std::string, std::string> nameshell;
struct passwd *p;
setpwent ();
while ((p = getpwent ()) != NULL)
nameshell[std::string (p->pw_name)] = std::string (p->pw_shell);
endpwent ();
for (const auto& e: nameshell)
if (e.second.find ("nologin") == std::string::npos)
std::cout << e.first << " uses " << e.second << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment