Automatic Importing from text files to a MySQL database using Automate by Network Automation

I am a raving fan of Network Automation’s products ( Automate is great for somebody such as myself who lacks a background in programming but is efficient at script writing. With Automate I am able to automate (as the product’s namesake) many tasks such as FTP, cleaning up file directories, downloading from a website, run reports, analyze reports, trigger email alerts, etc. all without the need to write lengthy scripts.

The scenario for this particular automate task was that we had text, CSV reports that we needed to import in to a MySQL database and needed to clear the particular table of all records before we started a new import. In order for this task to work we had to share the directory where the reports were at and need the task to loop through all of the files in the directory.

The task steps are as follows:

Step 1  Create a variable named “var_FilePath” with an initial value of “\\\\\\sharename\\” (Notice the double backslash. It’s a small nuance of MySQL that a backslash is a command character so you need a double backslash to represent a single backslash)
Step 2 Establish SQL Connection using…
NOTE: Here you use the built-in ODBC connection browser to connect to the MySQL database. IMPORTANT: You need to install the MySQL for Windows driver to be able to make this connection. You can get the driver at:
Step 3 Create a variable named “var_FullPath”
Step 4 Execute the SQL statement: “TRUNCATE TABLE tablename”
NOTE: Why use the TRUNCATE TABLE statement rather than UPDATE TABLE? There’s a great debate in online forums about the merits of both but in this instance we wanted a clean table so the TRUNCATE statement was more efficient.
Step 5 Loop through files in directory “\\\sharename” Do not include the path in the variable. Create and populate dataset “ds_files” with details of the file(s).
Step 6 Set variable var_Fullpath to value “%var_Filepath & ds_Files.Name%”
NOTE: So what is this about? We need the MySQL statement to grab the files from the shared directory but we needed the value to be in the right format. So this step concatenates the variable var_FilePath and the file name of the report so that we get the final value of \\\\\\share\\report.csv
Step 8 End Loop
Step 9 Close SQL Connection

And there you have it. In 9 easy steps I’m able to load 20 reports in to a table in under a minute!

Download the Automate AML task file

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s