Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #Mention shell in which the command lines will be executable
  2. #!/bin/bash
  3.  
  4. if [ $# -ne 1 ]
  5. then
  6. #echo command is used to display line of text/string that are passed as an argument
  7. echo "First check if user is local !! "
  8. echo "Τrying passwd"
  9.  
  10. #trying to find if the user ($ 1) exists in the path: etc/passwd
  11. #if user is found, then we have to print the 5th item (at line)which is users name
  12. awk -F: '{print $5}' /etc/passwd | sort -r | grep $1
  13.  
  14. else
  15.  
  16. echo "Check if user is remote !!"
  17. echo "Trying getent passwd"
  18.  
  19. # first the gatent passwd command looks for the user ($ 1) and then cuts the line #where containing it (with grep command).
  20. # then the result goes to awk command, to print the 5th item (at line), which is the #users name
  21.  
  22. getent passwd |grep $1 |awk -F: '{print $5}'
  23.  
  24. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement