1

I have a number of batch files, which all work when ran separably to back up various Postgres dbs across the network. However when ran through task scheduler the backup files aren't created. There are no job warnings or errors, nothing to indicate anything is wrong except that the files don't exist. There is nothing in the event logs either.

So how can I work out what is wrong and fix it, what should I look at first?

Mr Shoubs
  • 363
  • 2
  • 9
  • 32
  • Have you checked the logs? I'm assuming you're using Windows Server 2003 since it's Scheduled Task and not Task Scheduler. You should be able to go to **Advanced** at the top and **View Log**. Also double check the credentials. – Nixphoe Aug 03 '11 at 14:21
  • No, it's Task Scheduler - using 2008. I'm looking in the history and event logs. There is no Advanced option. Credentials checked. – Mr Shoubs Aug 03 '11 at 14:51
  • 1
    Try using exact path names and assume the `PATH` environment variable is empty or contains minimal entries. – Ben Pilbrow Aug 03 '11 at 14:51
  • I do already. Adding the answer below. – Mr Shoubs Aug 03 '11 at 15:15

1 Answers1

3

The only way I could find out what was going on is to add the following to the end of each line of the batch file:

>> C:\log.txt 2>&1
Mr Shoubs
  • 363
  • 2
  • 9
  • 32
  • Certainly - you're writing a program, it should have debugging within it if you need to know what it's doing wrong. You didn't see anything wrong in the logs because the task didn't have a problem running the script - the script wasn't doing what you wanted, which is not an error from the OS perspective. – mfinni Aug 03 '11 at 15:20
  • I can't accept it for a couple of days. :/ I think your correct, though as the script had a error ( pg_dump: [custom archiver] could not open output file "U:\VersionStore\versionstore.dump": No such file or directory The system cannot find the drive specified. )... I would have thought the scheduler would have picked that up. – Mr Shoubs Aug 03 '11 at 15:26
  • I'm guessing your trying to used mapped drives...that's not going to work. Also, the scheduler isn't going to catch errors in your script (that is your job). It will just report back the final errorlevel. – Doug Luxem Aug 03 '11 at 15:31
  • It doesn't report back anything other than success. see this question: http://serverfault.com/questions/297160/how-cant-i-make-pg-dump-write-to-a-shared-directory-when-running-from-task-sched – Mr Shoubs Aug 03 '11 at 15:40
  • You can monitor ERRORLEVEL for each command, and return an error from your BAT if you want the actual scheduled task to report an error. May be more trouble than it's worth, but if it makes sense for you, go for it. – mfinni Aug 03 '11 at 15:48