BASH   68

Make homes sh

Guest on 22nd September 2022 01:23:44 PM

  1. #!/bin/bash
  2.  
  3. grep /home /etc/passwd > /tmp/$$.tmp
  4.  
  5. USERS=`wc -l /tmp/$$.tmp | cut -d' ' -f 1`
  6.  
  7. allUIDs=(`cut -d ':' -f 3 /tmp/$$.tmp`)
  8. allGIDs=(`cut -d ':' -f 4 /tmp/$$.tmp`)
  9. allHomes=(`cut -d ':' -f 6 /tmp/$$.tmp`)
  10.  
  11. for (( i=0; $i<$USERS; i=$i+1 )); do
  12.    echo "i=$i"
  13.    echo "current UID:GID = ${allUIDs[$i]}:${allGIDs[$i]}"
  14.    echo "current home = ${allHomes[$i]}"
  15.    if [ ! -d ${allHomes[$i]} ]; then
  16.      echo "Making directory ${allHomes[$i]}"
  17.       mkdir ${allHomes[$i]}
  18.       chown ${allUIDs[$i]}:${allGIDs[$i]} ${allHomes[$i]}
  19.     fi
  20. done
  21.  
  22. rm -f /tmp/$$.tmp

Raw Paste


Login or Register to edit or fork this paste. It's free.