Jun 16

written by MG \\ tags:

Jun 16

Some times, while scripting, you need to print a sequence of letters or numbers. Don’t write it yourself ! Bash it using seq or curly braces!

Some examples:

#seq 1 3

1
2
3

# seq -s : 1 10
1:2:3:4:5:6:7:8:9:10

# seq -s : 0 2 10
0:2:4:6:8:10

#echo {1..10}

1 2 3 4 5 6 7 8 9 10

# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z

Building some hash directories :

# mkdir -p test/{1..5}/{1..5}

 

written by MG \\ tags: ,

Jun 04

export IGNOREEOF=1

Result when press Ctrl+d :

Ctrl+d
# Use “logout” to leave the shell.
Ctrl+d
# exit

written by MG \\ tags: ,

May 07

Securely delete a file called /tmp/login.txt:

shred -u /tmp/login.txt

You can add a final overwrite with zeros to hide shredding:

shred -u -x /tmp/login.txt

 Where,

  • -u : Remove file after overwriting
  • -x : Add a zero to hide shredding
  • -n NUM : Overwrite NUM times instead of the default 25

 

Shred a multiple files

Let us say you have 100 subdirectories and just wanted to get rid of all files:

 find -t f . -exec shred -u '{}' \;

Run shred on entire partition

shred -n 30 -vz /dev/hdb2

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: , , , ,