Catch 23
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:
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.ex e
- Add arguments: /c <path to the cmd file>
Any ideas what the limitation of the scheduled task could be?
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
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.ex
- Add arguments: /c <path to the cmd file>
Any ideas what the limitation of the scheduled task could be?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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!
ASKER
Thanks guys, the suggestion from Ben works like a charm.
Hey A Vader, glad to help :)
I would use Powershell to mail if whole thing was Powershell