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
btl2entrada

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
Alejandro85

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
Thread Forum
CSI Unable to Query Store Version Total count: 1
First I would like to say hello since I am new here. My issue is what it says in my title. I am sure I have some issues with the CBS.log as well. I have tried to correct the problem myself in multiple ways, but failed to do so. The system runs great except...sfc produces the following error when...
Windows Updates & Activation
Batch File on USB fails when Ran As Administrator
I am new to this site so please excuse any lack of etiquette I may show. I have recently built a .bat files to perform a large number of configuration changes needed for a Win7 or Win8 workstation to function properly on my network. The .bat file obviously needs to be ran with elevated...
Software
5.4 GB file fails to download
Hello! I'm trying to download 5.4 GB file from Google Drive and it fails at some point after 2/3. I tried to use several browsers but still the download fails with an error: "the file could not be saved, because the source file could not be read." Please help, i need it for my work badly! ...
Network & Sharing
Installing an .msi file fails - can't get into admin mode
This subject has been discussed before but none of the suggestions seem to work for me. I am trying to install MicrosoftCodecPack_amd64.msi file on my Windows 7 Home Premium system (64-bit). I'm the only user on this machine and I thought I had admin rights. However, when I try to install said...
Software
Windows 7 File Count
I need a little help from someone who has downloaded newer Windows 7 images... I have these builds: Build 6801: 751 Files, 147 Folders Build 7000: 793 Files, 150 Folders Build 7048 (x64): 811 Files, 157 Folders
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 11:26.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App