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.
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
At a glance
7 64bit
- OS
- 7 64bit