我的本地主机上有一个数据库,我需要使用批处理脚本将数据放入 MySQL 数据库。这可能吗?这些值在 .txt 文件中,但这不起作用。
这是我的整个脚本:
@echo on
setlocal ENABLEDELAYEDEXPANSION
set vidx=0
for /f "tokens=*" %%A in (C:\Users\Diana\Desktop\names.txt) do (
SET /A vidx=!vidx! + 1
snmpwalk -v 2c -c root %%A .1.3.6.1.2.1.25.3.3.1.2 > C:\Users\Diana\Desktop\cpu.txt
snmpwalk -v 2c -c root %%A .1.3.6.1.2.1.25.5.1.1.2 > C:\Users\Diana\Desktop\ramvid.txt
snmpwalk -v 2c -c root %%A .1.3.6.1.2.1.25.2.2 > C:\Users\Diana\Desktop\ram.txt
)
for /f "tokens=4" %%B IN (C:\Users\Diana\Desktop\ram.txt) DO echo %%B >> C:\Users\Diana\Desktop\ramfiltruotas.txt
for /f "tokens=4" %%B IN (C:\Users\Diana\Desktop\cpu.txt) DO echo %%B >> C:\Users\Diana\Desktop\cpufiltruotas.txt
for /f "tokens=4" %%a in (C:\Users\Diana\Desktop\ramvid.txt) do set /a used+=%%a
echo !used! > C:\Users\Diana\Desktop\naujas.txt
for /f "tokens=4" %%c in (C:\Users\Diana\Desktop\ram.txt) do set /a total=%%c
set /a ramai=(%used%*100)/%total%
echo %ramai% > C:\Users\Diana\Desktop\naujas2.txt
for /f "tokens=4" %%d in (C:\Users\Diana\Desktop\cpu.txt) do set /a e+=%%d
set /a cpu=(%e%/4)
echo %cpu% > C:\Users\Diana\Desktop\naujas3.txt
mysql --host=localhost --user=root --password= --database=database <
INSERT INTO server (cpu, ram)
WHERE ('server_name' LIKE '192.168.95.139'
VALUES (%cpu%,%ramai%)