Advertisement
Guest User

Untitled

a guest
May 10th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. user { "psareel":
  2. ensure => "present",
  3. uid => "37692",
  4. gid => "1",
  5. password => "OBUxaTBWqPKf.",
  6. comment => "Pt Sareel",
  7. home => "/home/psareel",
  8. shell => "/usr/local/bin/bash",
  9. }
  10.  
  11. run this with something like
  12. echo | ./shadow.awk
  13. ./shadow.awk <<< ""
  14.  
  15.  
  16. #!/usr/bin/awk -f
  17.  
  18. BEGIN {
  19. passwd_file="/etc/passwd"
  20. shadow_file="shadow"
  21. FS=":"
  22. }
  23.  
  24. {
  25. while (getline passwd < passwd_file) {
  26. if (split(passwd, passwd_array, ":") != 7) {
  27. print "problems reading passwd file"
  28. exit
  29. }
  30.  
  31. user=passwd_array[1]
  32. uid=passwd_array[3]
  33. gid=passwd_array[4]
  34. comment=passwd_array[5]
  35. home=passwd_array[6]
  36. comment => "PolicyKit,,,",
  37. home => "/var/run/PolicyKit",
  38. shell=passwd_array[7]
  39.  
  40. while (getline shadow < shadow_file) {
  41. if (split(shadow, shadow_array, ":") != 9) {
  42. print "problems reading shadow file"
  43. exit
  44. }
  45.  
  46. if (shadow_array[1] == user) {
  47. password=shadow_array[2]
  48. break
  49. }
  50. }
  51.  
  52. record=sprintf("user { \"%s\":\n", user)
  53. record=record "ensure => \"present\",\n"
  54. record=record sprintf("uid => \"%s\",\n", uid)
  55. record=record sprintf("gid => \"%s\",\n", gid)
  56. record=record sprintf("password => \"%s\",\n", password)
  57. record=record sprintf("comment => \"%s\",\n", comment)
  58. record=record sprintf("home => \"%s\",\n", home)
  59. record=record sprintf("shell => \"%s\",\n", shell)
  60. record=record "}\n"
  61. print record
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement