Jump to content

Batch File Help


needforspeed

Recommended Posts

Didn't know if this topic should go here or in programming or somewhere else so I'll try here :)

I wrote a batch file that will upload a log file to my ftp server, and when I manually run it, everything works fine. So I scheduled it using the AT command and it executes but doesn't work. If I use the /INTERACTIVE switch, I see the DOS window for it flash quickly on the screen, but I can't figure out a way to log the output of it. I tried to use the Scheduled Tasks thing in XP but it does the same thing. Any ideas on what the problem might be or how I can fix it?

Here's the file:

@echo off
setlocal

::Variables
set f=C:\ftpc.txt

::Compose ftp commands file
echo open SERVER-IP>>%f%
echo user USERNAME PASSWORD>>%f%
echo binary>>%f%
echo lcd "C:\Path To\Directory">>%f%
echo cd path-on-server>>%f%
echo put log.txt>>%f%
echo bye>>%f%

::Execute ftp command
::Use "-d" key for verbose output
ftp -n -d -s:%f% > C:\out.txt

::Cleanup
del /f /q %f%
endlocal

The file C:\out.txt never gets created when it's run as a scheduled event, but when I run manually, it's created and has the same output as the batch file (everything works fine). I can't figure out why it's not working when run by scheduler :unsure:

Link to comment
Share on other sites


A good way to understand why it does not work is to put some

PAUSE

statements between lines.

This will stop the execution of the batch until you press a key, so that you can inspect C:\ftpc.txt with Notepad and see if anything is wrong.

Also REM out this:

REM ftp -n -d -s:%f% > C:\out.txt

and change it to

ftp -n -d -s:%f%

PAUSE

this way you'll see the error (if any) in the ftp part.

jaclaz

Link to comment
Share on other sites

you could try and rename your bat file to a *.vbs file to see if it works, you could also try and convert the bat file to an *.com or *.exe file.

Another solution which I use because I have alot of bat files that run at night, I use a program called Schedule Wizard, which allows me to schedule bat files. Do a search on google.com for the web page.

Link to comment
Share on other sites

Well I haven't searched for schedule wizard yet, but I've tried the other suggestions from you guys and now the task scheduler won't run any tasks. Every one says "Could not start" in the status column, no matter if I drag and drop a batch file there or use the AT command. Got any ideas on that? I've been googling and get a lot of info about batch files but nothing that seems to help.

Thanks for the replies so far guys.

Link to comment
Share on other sites

Actually, if you are on XP, you should NOT use the AT command, which is mantained for backwards compatibility.

See here:

http://www.ss64.com/nt/at.html

you should use schtasks:

http://www.ss64.com/nt/schtasks.html

Also, batch files under NT/2K/XP/2003 should have extension .cmd, not .bat, see here:

http://home.earthlink.net/~rlively/MANUALS...MANDS/C/CMD.HTM

Renaming it to .vbs is pure nonsense

Finally you might have the extension improperly registered, if so try running it like this:

C:\WinNT\System32\CMD.EXE mybat.cmd

jaclaz

Link to comment
Share on other sites

Actually, if you are on XP, you should NOT use the AT command, which is mantained for backwards compatibility.

See here:

http://www.ss64.com/nt/at.html

you should use schtasks:

http://www.ss64.com/nt/schtasks.html

Also, batch files under NT/2K/XP/2003 should have extension .cmd, not .bat, see here:

http://home.earthlink.net/~rlively/MANUALS...MANDS/C/CMD.HTM

Renaming it to .vbs is pure nonsense

Finally you might have the extension improperly registered, if so try running it like this:

C:\WinNT\System32\CMD.EXE mybat.cmd

jaclaz

Thanks for the links, I've scheduled the task with schtasks and it appears in the scheduled tasks window, but it still says "Could not start". I also renamed it to .cmd.

When I run it with C:\WinNT\System32\CMD.EXE mybat.cmd (changed to work for mine obviously), it's still not working.

I don't understand the Could not start, it's doing that for every task now, no matter what I add.

edit----

Ok, I found out where the log file is at for the scheduled tasks, and it looks like it's claiming that it can't find the file to execute. Using the AT command, it apparently didn't know what account to use to execute it. I'll keep trying with this....

Edited by needforspeed
Link to comment
Share on other sites

@echo off
setlocal

::Variables
set f=C:\ftpc.txt

PAUSE

::Compose ftp commands file
echo open 192.168.1.50>>%f%
echo user incoming PASSWORD>>%f%

PAUSE

::echo binary>>%f%
echo ascii>>%f%
echo lcd "C:\Program Files\Folding@Home">>%f%

PAUSE

echo cd viper>>%f%
echo put FAHlog.txt>>%f%

PAUSE

echo bye>>%f%

::Execute ftp command
::Use "-d" key for verbose output
:: ftp -n -d -s:%f% > C:\out.txt
::start /MIN /WAIT ftp.exe -n -d -s:%f% > C:\out.txt

ftp -n -d -s:%f%
PAUSE

::Cleanup
del /f /q %f%
endlocal

That's the exact code except for my password to the ftp server. If I just double click on the .cmd file, everything works correctly, it pauses, the new file gets uploaded, it's all good. But, if I use the wizard to schedule this task, I see the DOS window on the screen for an instant, then it's gone, I never had to press a key to make it continue or anything. I don't understand it :no: help please!

This thing is supposed to just upload the log file for my folding clients to my server, so they are all in a central place and I can check up on them daily from anywhere. I'm starting to wonder if it's not something completely rediculous like the @ sign in the path to the .cmd file or something.

--EDIT---

I think I was right about the @ sign, I put the file in the root of C: an scheduled it and it worked.....Now, I need to figure out how to make it not flash the DOS screen, I want it to be completely silent.

Edited by needforspeed
Link to comment
Share on other sites

QuickBatchFileCompiler can create silent exes that are essentially the contents of batch files. There's an option with the program to make the program silent. The only downside - it's not free.

Link to comment
Share on other sites

QuickBatchFileCompiler can create silent exes that are essentially the contents of batch files. There's an option with the program to make the program silent. The only downside - it's not free.

I got it working the way I want using the AT command. But I tried that program anyway, and of course it pops up a message which is fine for testing, but a new file wasn't uploaded. Oh well, now I've got to play with getting this to work on 98 and ME.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...