Mkdir but better: with date stamp on created dir

Linux takes care of date modified on files and folders, so i played around shell scripting to create my own where i can create dirs with date stamp on them. This is how it works.

mkdatedir <path> <directory name>

step by step

[saurap@saurap /]# vi mkdatedir

#!/bin/bash
day=”`date +%m“date +%d“date +%y`”
folder1=”$2″”$day”
cd $1
mkdir $folder1

save the file and create a symbolic link of it on /sbin

add path ./ to your $PATH

viola

now you have the command ready to execute….

example

[root@meadow cloud]# ls
a b c d e f g h i lost+found m n
[saurap@saurap cloud]# mkdatedir /cloud saurap
[saurap@saurap cloud]# ls
a b c d e f g h i lost+found m n saurap112111

Advertisements

run automatic backup on usb as soon as it’s plugged in

[root@saurap /]# cat /proc/scsi/usb-storage/*
Host scsi27: usb-storage
Vendor: Sony
Product: Storage Media
Serial Number: 2A07060549833
Protocol: Transparent SCSI
Transport: Bulk
Quirks:

[root@saurap saurap]# vi /etc/udev/rules.d/pendrive.rules
#BUS=”usb”, SYSFS{serial}=”2A07060549833″, SYMLINK=”Storage\ Media”, RUN+=”/home/saurap/penback.sh”
OR
SUBSYSTEMS==”usb”, ATTRS{serial}==”2A07060549833″, SYMLINK+=”Storage”, RUN+=”/home/saurap/penback.sh”

Then create the penback.sh script for backup as

vi penback.sh
#!/bin/bash
mount /dev/sdb1 /media/PEN
sleep 3
rsync -zvr /home/saurap/Desktop/mine/ /media/PEN/backup