Lazy script for new machines

Because I’m lazy I’ve thrown together a basic script to create a folder for the machine, add a hosts record for resolution and perform and output the results of an initial nmap scan to the newly created folder and felt like sharing.

Depending on if you are root, you may have to give permissions to /etc/hosts for your user.

to run ./scriptname.sh IP SERVERNAME

#!/bin/bash
IP=$1
LOC=$2
HTBfolder="htb"
ports=$(nmap -p- --min-rate=1000 -T4 $IP | grep ^[0-9] | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)
[ -d "~/$HTBfolder" ] && echo "Directory ~/$HTBfolder already exists" || mkdir ~/$HTBfolder
[ -d "~/$HTBfolder/$LOC" ] && echo "Directory ~/$HTBfolder/$LOC already exists" || mkdir ~/$HTBfolder/$LOC
nmap -sC -sV -p$ports $IP > ~/$HTBfolder/$LOC/nmapresult
echo $IP $LOC.htb >> /etc/hosts
echo "Added $LOC.htb on $IP to /etc/hosts"
echo "NMAP Report Complete: ~/$HTBfolder/$LOC/nmapresult"