Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. DBFILE=linuxusers.db
  2. PASSWDFILE=/etc/passwd
  3. TABLENAME="USERS"
  4.  
  5. if ! [ -r "$PASSWDFILE" ]
  6. then
  7. echo "Could not read $PASSWDFILE. Exiting..."
  8. exit 1
  9. fi
  10.  
  11. echo "Preparing database file $DBFILE now..."
  12. sqlite3 "$DBFILE" "DROP TABLE IF EXISTS $TABLENAME;"
  13. sqlite3 "$DBFILE" "CREATE TABLE $TABLENAME (username not null, uid integer not null, gid integer not null, homedir text not null)"
  14. echo "Database prepared, filling..."
  15.  
  16. ALL="$(grep -E "^([a-z0-9]*tux)|(vm[a-z0-9]*)|(root):" testpasswd | cut -d':' -f 1,3,4,6)"
  17.  
  18. echo "$ALL" | while read line
  19. do
  20. _USER="$(echo "$line" | cut -d':' -f1)"
  21. _UID="$(echo "$line" | cut -d':' -f2)"
  22. _GID="$(echo "$line" | cut -d':' -f3)"
  23. _HOMEDIR="$(echo "$line" | cut -d':' -f4)"
  24. sqlite3 "$DBFILE" "INSERT INTO $TABLENAME VALUES ('$_USER', $_UID, $_GID, '$_HOMEDIR');"
  25. done
  26.  
  27. echo "Database filled. Printing results:"
  28. sqlite3 -header "$DBFILE" "SELECT username, gid, uid, homedir FROM USERS";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement