Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


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


19 Sep 2012   #1

7 64bit
 
 
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 System SpecsSystem Spec
.

23 Sep 2012   #2

Windows 7 Ultimate x64
 
 

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 System SpecsSystem Spec
Reply

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




Thread Tools



Similar help and support threads for2: bat file fails(not sure why):query postgresdb then ftp txt if count>0
Thread Forum
Solved CSI Unable to Query Store Version Total count: 1 Windows Updates & Activation
5.4 GB file fails to download Network & Sharing
Batch file to stop services fails Performance & Maintenance
DirectX install fails... something about a cabinet file. Windows Updates & Activation
SF Diagnostic Tool fails to copy .dmp file BSOD Help and Support
Windows 7 File Count Chillout Room

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 12:06 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33