Script to delete files on a Windows 7 or 2008 box

So recently I found myself needing to do some log management of some custom logs I was writing to disk. Put this guy in a .bat file and use task manager to keep things in check:

forfiles -p “c:\logs\nginx” -s  -m *.* -d  -1 /C “cmd /c del @PATH”

Two important things to watch out for. After the path CAN NOT include a backslash ‘\’ That will stop it from running. Second, after the -d is the number of days old that you want it to delete. 

Maybe next I’ll create a script to zip the logs and ship them off somewhere.

Advertisements

Accessing LVMs from CentOS Rescue

Recently, I had the fun (pain) of recovering a CentOS box with a corrupted logical volume. Below are the steps I took.

1. Boot to a CD/DVD and enter rescue mode from the menu
2. When the menu option for automatically mounting is offered, select no
3. Create a space to mount the disk. If you’re a purest, /mnt/sysimage is fine
4. Next, key in “lvm vgscan -v”
5. Now that we have the disk, we can tell the kernel about the vg, we do this with “lvm vgchange -a y”
6. You should have received a message about the vg being active now, great now we can mount the logical volumes like you would with a physical drive. Use lvm lvs –all to list all the available logical volumes.

in my case, my lv_home became corrupt. Not sure what happened, but we’ll take a look at logs later.

To remove the lv, we’ll do:

lvremove /dev/mapper/vg_name_lv_home

CentOS will prompt us if we’re sure we want to do this. You can use -an to automatically respond yes if you find yourself scripting this.

Now, we’ll recreate the logic volume.

lvcreate -L <size> -n lv_home vg_name

Don’t forget to format the new lv!

mkfs.ext4 /dev/mapper/vg_name_lv_home

Now you can mount the drive to /mnt/sysimage/home

or just reboot.