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


  1. Posts : 1
    7 64bit
       #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


  2. Posts : 2,468
    Windows 7 Ultimate x64
       #2

    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


 

  Related Discussions
Our Sites
Site Links
About 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 15:29.
Find Us