bat file fails(not sure why):query postgresdb then ftp txt if count>0

btl2entrada

New member
Local time
9:50 AM
Messages
1
bat file fails(not sure why):query postgresdb then ftp txt if count>0

i have a bat file that i am using for basic monitoring. i have it run every 30 minutes in task scheduler. I finally got it to where it runs but it quits early. i dont know why. Code below. Any help is welcome.
Code:
@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
where /r E:\ psql > text.txt
where /r D:\ psql >> text.txt
where /r F:\ psql >> text.txt
where /r C:\ psql >> text.txt
for /F "tokens=1,2* delims=," %%i in (text.txt) do (
set PGdrive=%%~di
set PGpath=%%~pi)
del text.txt
%PGdrive%
cd %PGdrive%%PGpath%
::YOU MUST CHANGE THE DATABASE NAME AT THE END OF THE QUERY --->
FOR /F "tokens=*" %%i in ('psql -U postgres -q -t  -c "select count from table" DBNAME) DO set count=%%i
IF !count! NEQ 0 (
echo "Something went wrong in the last 30 minutes." > C:\batchfiles\results2.txt
where /r E:\ winscp.com > text.txt
where /r D:\ winscp.com >> text.txt
where /r F:\ winscp.com >> text.txt
where /r C:\ winscp.com >> text.txt
for /F "tokens=1,2* delims=," %%i in (text.txt) do (
set windrive=%%~di
set winpath=%%~pi)
del text.txt
!windrive!
cd !windrive!!winpath!echo option batch abort > winscpcmd.txt
echo option confirm off >> winscpcmd.txt
echo open ftps://USERNAME:PASSWORD@SERVERIP:PORT -implicit >> winscpcmd.txt
echo put C:\batchfiles\results2.txt >> winscpcmd.txt
echo close >> winscpcmd.txt
echo exit >> winscpcmd.txt
winscp.com /script=winscpcmd.txt > NUL 2>&1
del winscpcmd.txt
del C:\batchfiles\results2.txt)
 

My Computer My Computer

At a glance

7 64bit
OS
7 64bit
Look at some suggestions here: windows - How can I debug a .BAT script? - Stack Overflow

Basically, to test it out, remove the ECHO OFF and carefully watch the output to see which line ran and which one was skipped. Windows has the /Y on cmd.exe to step though bat files that would have been THE perfect option for this, but was "wisely" removed from Windows.
 

My Computer My Computer

At a glance

Windows 7 Ultimate x64Intel Core i7-740QM8 GB DDR3NVIDIA GeForce 330GT
Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Sattelite A665-S6092
OS
Windows 7 Ultimate x64
CPU
Intel Core i7-740QM
Memory
8 GB DDR3
Graphics Card(s)
NVIDIA GeForce 330GT
Screen Resolution
1366x768
Hard Drives
Samsung 840 SSD 500GB
1TB USB3 external HD
Cooling
Coolermaster Notepal U3 notebook cooling pad
Internet Speed
3mbps ASDL
Antivirus
ClamWin 0.98.7
Browser
Opera 12.17 x86 (main), Firefox 38 (sec), IE11 (last resort)
Back
Top