-3

I have CSV file with this format:

column 1: Asset Name - FW_Prod
column 2: Asset Group - All FW's

In my MySQL I have table for all assets and another one for the Asset group.

How can I write MySQL query that will help me to update Asset Group table with information from 'All Asset'?

I want to take the information from the CSV file and update AssetGroup table with that information.

import sys
print sys.argv[0]
with open(sys.argv[0], 'r') as Fin:
with open('SQLoutAssetsToGroups.sql', 'w') as Fout:
    Fout.write("use skyboxview_live;\n\n")
    for line in Fin:
        newline = line.strip().split(';')
        AssetName = newline[0]
        AssetGroupName = newline[0]
        print "Asset "+AssetName+" Assign To Asset Group         "+AssetGroupName+"."
        # MYSQL - Assign the interface network to Zone

        Fout.write("update sbv_host_groups set sbv_host_groups.name=\'"+AssetGroupName+"\' where sbv_hosts.name_from_user\'"+AssetName+";\n")

Please find a script that actually works for the another purpose: import sys

print sys.argv[1]
with open(sys.argv[1], 'r') as Fin:
with open('SQLoutNetZoneByNet.sql', 'w') as Fout:
    Fout.write("use skyboxview_live;\n\n")
    for line in Fin:
        newline = line.strip().split(';')
        NetworkName = newline[0]
        Network = newline[1].split('/')[0].strip()
        SM = newline[1].split('/')[1].strip()
        ZoneName = newline[2].strip()
        print "Interface Name "+Network+" Subnet"+SM+" . Assign To Zone "+ZoneName+"."
        # MYSQL - Assign the interface network to Zone

        Fout.write("update sbv_networks set sbv_networks.name=\'"+NetworkName+"\' , zone_category_guid=(select sbv_zone_categories.global_unique_id from sbv_zone_categories where sbv_zone_categories.name=\n")
        Fout.write("\'"+ZoneName+"\' ) where INET_NTOA(ip_address)=\'"+Network+"\' and net_mask=\'"+SM+"\';\n")
Or Maman
  • 1
  • 2

1 Answers1

0

This has been somewhat answered in this post. Doing little bit of research and showing some work you have done makes it vivid for us to provide assistance wherever is needed.

How do I connect to a MySQL Database in Python?

Community
  • 1
  • 1
Jake Wagner
  • 786
  • 2
  • 12
  • 29