Created
April 24, 2015 20:17
-
-
Save mirekfranc/30fe3817183347c854f0 to your computer and use it in GitHub Desktop.
Which user uses which shell on unix in C++11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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