Thursday, July 8, 2010

Automated Nessus scan from command line.

This handy little script will run a nessus scan against a IP range. I use this in a crontab to run automated scans and dump the results into a directory with a file name that has a time stamp in it.
Make sure that you have a config for your scan already done (this is used for the Nessus_scan_config below). Put your ranges for IP's in the text_file_of_scan_ranges.txt (ie 192.168.1.1-192.168.1.254).

#!/bin/sh


today=$(date +%Y%m%d)


/opt/nessus/bin/nessus -c /opt/nscans/configs/Nessus_scan_config -xq nessus.server 1241 username password /opt/nscans/targets/text_file_of_scan_ranges.txt /opt/nscans/reports/IP_range-$today.html


mkdir /directory_you_want_scans_in/$today

mv /opt/nscans/reports/IP_range-$today.html /directory_you_want_scans_in/$today

Tuesday, July 6, 2010

Delete files and folders older then 30 days

Just stumbled on this function and had a need to delete temp files that were 30 days old. This works great and I split it out to delete sub folders as well!

@echo off

rem ##### Script deletes files and folders older then 30 days #####

echo deleting files older then 30 days

rem ##### this checks and deletes files that are older then 30 days #####
rem ##### in server 2008 if you delete files first then the date stamp changes on directories so directory delete is done first #####
forfiles /p "c:\temp" /s /d -0 /c "cmd /C del @FILE /q"


rem ##### this checks and deletes directories and sub directories that are older then 30 days #####
ForFiles /P "c:\temp" /D -0 /C "cmd /c if @isdir==TRUE RD /Q /S @FILE "

Friday, July 2, 2010

bash script to create incremental multiple lines in a file

I used this script to create a default file for pxelinux.cfg. It could be used for anything that needs almost identical lines added to a file. In this instance I have multiple esx servers and if I want to install/re-install them using a pxe boot environment all I need to do is select the correct server and off I go!

#!/bin/bash

for i in {001..999}
do
echo "label $i" >> default
echo "menu label $i" >> default
echo "kernel esx/vmlinuz" >> default
echo "append initrd=initrd.img vmkopts=debugLogToSerial:1 mem=512M quiet ks=http://IP_address/kickstart_file" >> default
done