Jan 26

#!/bin/bash
for x in `find * -maxdepth 0 -type d`;
do
  # Translate Caps to Small letters
  y=$(echo $x | tr ‘[A-Z]’ ‘[a-z]’);

  # check if directory exits
  if [ ! -d $y ]; then
     echo “mv $x $y”
     mv $x $y;
  fi
done

NOTE: -maxdepth 0 is for directories in curent dir. If you want to rename in depth use -depth instead

written by MG \\ tags: , , , ,

May 07

#!/bin/bash
HOME_BASE=”/home/”  #set your home base directory
SHELL=”/bin/bash”  #set shell for users

#checking if you are root
if [ $(id -u) -eq 0 ]; then

read -p “Username:” USER
read -s -p “Password:” PASSWORD

egrep -w “^$USER” /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
    echo -e “\n$USER exists!\n”
    exit 1
else
    PASS=$(perl -e ‘print crypt($ARGV[0], “password”)’ $PASSWORD)
    useradd -p ${PASS} -s $SHELL -m -d ${HOME_BASE}${USER} ${USER}
    [ $? -eq 0 ] && echo -e “\nUser has been added to system!\n” || echo -e “\nFailed to add a user!\n”
fi

else
    echo -e “\nOnly root may add a user to the system\n”
    exit 2
fi

save it like script.sh and run it with: ./script.sh

written by MG \\ tags: , , , ,