Jump to content

Automate things Using Script2Email and Cron


Mark G

Recommended Posts

i have had the Turtle for about 2 weeks. I have setup OpenVpn and it works great. when it came to doing script2email and Cron i couldnt find any documentation on this so i decided to create my own to help others out.

Couple of thing you need first:

1. Script2email needs to be setup on the lan turtle. find this in lan turtle modules script2email - Configure - Edit Script
This sends me the Nmap results, Uptime, And network configs.

     This is My script 

#uptime
echo -e "UPTIME\n"
uptime
echo -e "*****************************************\n"
echo -e "\n"
echo -e "NMAP LOGS\n"
cat attachments.tar.gz
echo -e "*****************************************\n"
echo -e "\n"
echo -e "NETWORK CONFIGS\n"
ifconfig
 

2. Setup you email with these configs below change YOUREMAIL and PASSWORD to your
account.  This config worked for me.

From:  youremail@gmail.com
To: youremail@gmail.com 
Mail:  SMTP.gmail.com:587 
Domain:   gmail.com 
Host:   smtp.gmail.com:587 
User:  youremail@gmail.com 
Password:  yourpassword 

3. Get back to the command line and create a directory  /etc/nmaplogs this can be done by typing  " mkdir /etc/nmaplogs  " without the ".


4. Now that we have the email and email script and folder created we need to setup nmap-scan.
Goto Nmap-scan in modules then Configure 
Set the target Example: 192.168.1.1-254
Set the Profile to Quick Scan
Set the Log to /etc/nmaplogs/   Make sure you put all the forward slashes in there or it will not work. 
Do not execute 
Go Back

5. No we need to Make a Script on the command line.
Back at the command line Type    cd    then press enter 
Then enter " echo >> my  "
Then enter "  nano my  "
This will bring up an editor, add the script below and use CTRL X to save the file 
##########################################################

#!/bin/sh
# Settup you nmap scan with a log folder called "nmaplogs" do this by going to $
# Setup your Ip range to scan in the nmap module and select you profile

start nmap-scan
echo "Please Wait 60 seconds as Nmap-Scan is running"
sleep 10
echo "50"
sleep 10
echo "40"
sleep 10
echo "30"
sleep 10
echo "20"
sleep 10
echo "10 Almost there. Hang Tight."
sleep 10


# This will Append the log files to one file for email
tar -cvf attachments.tar.gz /etc/nmaplogs
echo "Creating File For Email"
sleep 10
echo "File DONE"

# This will Start the script to email
# My scipt is     "  */30 * * * * ./my   " Without the quotes. This runs every $
start script2email

echo "Sending EMail"
sleep 15
echo "Email Sent"
sleep 5
echo "Cleaning Up Files"

#This will Cleanup the files


##################################################


after saving the file we need to make it executable type "   chmod u+x my      "
Now the File will be executable.
We are done setting up the script. 

6. Now we need to test the Script type "    ./my    " in the command line this will take about 1-2 Minutes to finish. If all went well you should have and email containing the Uptime, nmap results, and Netwrok Configs.


7. Now we can setup Cron to do this script auto at set times of the day week month or year. 
Go back into the modules goto cron and configure I used this below to send me and email every 30 minutes. 
add this line 
*/30 * * * * ./my

Click ok after adding. 
Dont forget to enable this module 
no need to add any other line as this is all ran in the my script we created. 
 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...