Empulse Group a collection of notes from a sys admin, musician, and father

14Aug/12Off

Here is a small bash script that will create a user from a list that you can pipe it complete with setting and printing a random password. This was for mail users so I set the shell to false.

#!/bin/bash

while read USER; do
   PASS=`< /dev/urandom tr -dc A-Za-z0-9_ | head -c8`
   /usr/sbin/useradd -s /bin/false $USER
   echo $PASS | passwd $USER --stdin
   echo "User: $USER / Pass: $PASS"
done;
12Aug/12Off

VIM tips

Here are tips for moving around in VIM while in command mode:
press 0 (zero) to jump to the beginning of the line
press $ to jump to the end of the line
press :7 to jump to line 7
press gg to jump to the beginning of the file
press G to jump to the end of the file
press dd to delete the current line
press u to undo
press control+r to redo
press yy to yank (copy) the current line
press P to put (paste) before the current line
press p to put after the current line
press /string to search for "string" in the file, going forward
press ?string to search for "string" in the file, going backwards
press n to repeat search in same direction
press N to repeat search in reverse direction
press :noh to clear you search to remove highlighting
press :%/search/replace/g to replace each instance of "search" with "replace"
press A to insert after the end of line


Tagged as: , , Comments Off
12Aug/12Off

file count BASH script

#!/bin/bash
# 20120812
# by: eric hernandez
#
# usage: ./file_count [path]
#
for DIR in `find $1 -type d`; do
   COUNT=0
   for FILE in $DIR/*; do
      if [ -f $FILE ]; then
         ((COUNT++))
      fi
   done
   echo -e "$COUNT \t $DIR"
done
Tagged as: , Comments Off