Link to home
Start Free TrialLog in
Avatar of Catch 23
Catch 23Flag for Netherlands

asked on

CMD file - Alert mail not sent from scheduled task.

I have a CMD file that connects to an FTP server to transfer files. When the FTP server is unavailable, an alert email should be sent by a seperate Powershell script. Everything works fine when I run the script form a Command Prompt, when the CMD file is executed by a scheduled task the mail is not sent.

Since there is no problem when the batch file is executed from a command prompt, I guess the problem must be located in the scheduled task-settings, not in the script.

Batch file details:
<code to connect to the FTP server>
if %ERRORLEVEL% neq 0 goto error
 
echo Upload succeeded, moving local files
<code to move the files from the local drive to the FTP server>
exit /b 0
 
:error
powershell.exe -ExecutionPolicy Bypass -Command ".\mail.ps1"
exit /b 1

Open in new window


Scheduled task details:
- runs with administrator account
- run whether user is logged on or not
- run with highest priviliges
- Action: Start a program
- Program/script: C:\Windows\System32\cmd.exe
- Add arguments: /c <path to the cmd file>
 
Any ideas what the limitation of the scheduled task could be?
SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would use blat https://sourceforge.net/projects/blat/ and natively call it from the batch file.
I would use Powershell to mail if whole thing was Powershell
Hey Shawn,

  I used to use Blat, I switched over to using a Powershell script I wrote to send email as well.

  Personally, I don't like to have to install and maintain 3rd party executables myself, and the PowerShell is easy to use.

  But it's a matter of preference really.

Ben
My point is that I would do away with the bat file completely and use Powershell (one script) to do FTP, move file and Notification
Avatar of Catch 23

ASKER

The longterm solution will be a complete powershell script for transferring the data and generating alert messages. For the short term I'll try the suggestion that Ben Personick gave and post the result. Thanks!
Thanks guys, the suggestion from Ben works like a charm.
Hey A Vader, glad to help :)