Jump to content
Ketarin forum

SwithMail update alert with log file of error


itskytech
 Share

Recommended Posts

Hi everyone,

 

I'm using Ketarin to update a large application repository in a Toolbox of a software we use at work.

It work on a server with a Windows task /silent /notify once a week.

 

For now, we receive email notification of application that has been updated with the SwithMail arguments:

/subject "Ketarin update {appname:replace:&:^&}" /body "{appname:replace:&:^&} {version:replace:&:^&}"

I'm wondering if there any simple way to get email also when an error occur on the update of an application, or maybe a command to save all errors on a log file and then we can send the attachment as well with the email?

 

I browsed this forum a lot and never find something that could achieve that.

 

 

Thanks for that really great software!

Link to comment
Share on other sites

I treat any versionless run as a failure. Sure, sometimes a failure occurs even if the version is correct, but this is the most effective testing for me.

 

So, in the global 'before updating' function I use 

if "{version}"=="" echo ERROR /// {category:replace:&:^&} /// {appname:replace:&:^&} >> somefile.txt
if "{version}"=="\{version\}" echo ERROR /// {category:replace:&:^&} /// {appname:replace:&:^&} {version:replace:&:^&} >> somefile.txt
if "{version}"=="" exit 1

In the global 'after updating an application' I use:

echo {category:replace:&:^&} /// {appname:replace:&:^&} {version:replace:&:^&} >> somefile.txt

In the global 'after updating all applications' you can use your existing command, and either attach or read in 'somefile.txt' for the body.

Link to comment
Share on other sites

Thanks for the reply!

 

I will definitely add that to my script.

 

 

EDIT: Here is what I ended up doing for this:

 

Before updating:

if "{version}"=="" echo ERROR /// {category:replace:&:^&} /// {appname:replace:&:^&} >> log.txt
if "{version}"=="\{version\}" echo ERROR /// {category:replace:&:^&} /// {appname:replace:&:^&} {version:replace:&:^&} >> log.txt
if "{version}"=="" exit 1

After updating:

echo {category:replace:&:^&} /// {appname:replace:&:^&} {version:replace:&:^&} >> log.txt

After updating all:

SwithMail.exe /s /from "YOUREMAIL@DOMAIN.COM" /name "SENDER NAME" /a "C:\Program Files (x86)\Ketarin\log.txt" /server "YOUR SMTP SERVER" /p "25" /to "RECEIVER@DOMAIN.COM" /subject "Toolbox update" /body "All application has been updated, error is in the log file attachment."
ping 1.1.1.1 -n 1 -w 10000 >nul
break > "C:\Program Files (x86)\Ketarin\log.txt"

Thought it will be nice to share the whole script if anyone need a same functionality, the log file is written at your Ketarin install folder. For the "after updating all" I use a ping to delay the clear of the log file, so the file have time to send by email before it clear out and if in any case you don't have any error, the email will send anyway because the log file is there! (Instead of deleting it each time)

Link to comment
Share on other sites

I would suggest pinging 127.0.0.1 instead if you're going to impose a delay with ping, that way you don't have to try to touch outside your network (and risk breaking any security policies you have in place). APNIC Labs might be happy for it too. :)  If you just want the delay without actual network traffic, use 0.0.0.0

Link to comment
Share on other sites

  • 1 month later...
On 26.4.2017 at 2:25 PM, itskytech said:

SwithMail.exe /s /from "YOUREMAIL@DOMAIN.COM" /name "SENDER NAME" /a "C:\Program Files (x86)\Ketarin\log.txt" /server "YOUR SMTP SERVER" /p "25" /to "RECEIVER@DOMAIN.COM" /subject "Toolbox update" /body "All application has been updated, error is in the log file attachment."
ping 1.1.1.1 -n 1 -w 10000 >nul
break > "C:\Program Files (x86)\Ketarin\log.txt"

 

Instead of specifying the complete installation path, I would use

"{startuppath}log.txt"

This makes it more flexible if you want to use Ketarin from a external hard disk for example.

Link to comment
Share on other sites

Hi all, 

I have following in my command after updating all apps.  Swithmail.exe is placed in the katerin folder.  I do not have it as variable in the global commands.

Should I do it ?  like this ?  variable = swithmail  content = "C:\portable files\ketarin\swithmail.exe"  ? 

My problem is that the below does not work...  Where is the error ?  a changed the port also from 25 to 465.  non of them work.

Quote

SwithMail.exe /s /from "myemailadres1@gmail.com" /pass pwofemail1 /server smtp.gmail.com /p 465 /to "myemailadres2@gmail.com" /subject "KetarinToolbox update" /body "All application has been updated, error is in the log file attachment."
ping 0.0.0.0 -n 1 -w 10000 >nul
break > "{startuppath}Ketarinlog.txt"

Thanks in advance for the support of possible solution.

Link to comment
Share on other sites

Based on those settings I suspect the problem is most likely the unquoted password or LSA access. Passwords tend to have non-alphanumeric characters, and if the password has a caret (^), ampersand (&), parenthesis ("(" or ")"), space, doublequote ("), or one of several other characters then it'll fail to authenticate because those characters are being treated differently from the command line. You should be able to check the errorlevel to determine if that's that case:

swithmail.exe ...

IF %errorlevel%==1 ECHO.Something is wrong with sending email.

If it's really a Gmail account then the other likely issue is that you haven't yet enabled LSA/"less secure apps" for that account. Verify that this is enabled and try again.

Link to comment
Share on other sites

note on passwords - if the password has a special character then quoting will help but in some cases (such as caret, pipe and doublequote) will still need to be escaped for it to work. Use a caret to escape most characters, and echo to test it:

ECHO. This is the quoted password: "Princess^|1"

 

Link to comment
Share on other sites

Did you test for the errorlevel? Did you run the command outside of Ketarin to determine if it's a path problem, or maybe a permissions problem, or get visual feedback?

Please post a sanitized example of your swithmail command line - change ONLY the email address and password to a generic value (like "user@gmail.com" and "mypassword"). Leave server names, ports, path, and other values the same as they are. I'll test it my next visit to the forum.

Link to comment
Share on other sites

== Following 2 lines I have in settings 'after update of application' :

echo %date% - %time% // {appname} v{version} - {file:targetpath} >> "{root}\centralfiles"\KetarinHistory.txt
echo {category:replace:&:^&} /// {appname:replace:&:^&} {version:replace:&:^&} >> Ketarinlog.txt

== Following 3 lines as is 'after updating ALL applications' :

SwithMail.exe /s /from "emailsender@gmail.com" /pass "myexactpassword" /server smtp.gmail.com /p 25 /to "emailreceiver@gmail.com" /subject "KetarinToolbox update" /body "All application has been updated, error is in the log file attachment."
ping 0.0.0.0 -n 1 -w 10000 >nul
IF %errorlevel%==1 ECHO.Something is wrong with sending email.

I see no sending nor receiving email in both diff. email accounts.

I copied these lines from this forum somewhere.  Swithmail.exe is located in the ketarin.exe folder.

Link to comment
Share on other sites

  • 2 weeks later...

the first echo line is going to be problematic. any app name with an ampersand is going to create issues. as will other special characters. it also has embedded quotes which might create issues. I'd change it to this:

echo.%date% - %time% // {appname:replace:&:^&} v{version:replace:&:^&} - "{file:targetpath}" >> "{root}\centralfiles\KetarinHistory.txt"
echo.{category:replace:&:^&} /// {appname:replace:&:^&} {version:replace:&:^&} >> "{root}\centralfiles\Ketarinlog.txt"

the swithmail line doesn't actually have an attachment.

the errorlevel check is after ping, so it's checking the error status of ping NOT the error status of swithmail. 

have you tried running ONLY the swithmail line on its own in a command prompt window? (no, it won't have the attachment, but it might report an errorlevel that tells you why it failed)

to add an attachment you'll need to use this syntax -- note that i added "/test" so you could get a visual indicator of failure:

SwithMail.exe /TEST /s /from "emailsender@gmail.com" /pass "myexactpassword" /server smtp.gmail.com /p 25 /to "emailreceiver@gmail.com" /subject "KetarinToolbox update" /attachment "{root}\centralfiles\KetarinHistory.txt" /body "All application has been updated, error is in the log file attachment."

 

Link to comment
Share on other sites

and finally, you don't need to use ping since swithmail has its own return code - which means it doesnt execute outside of the current process. the cmd should wait and not move on to the next line until it has completed and returned either success or failure.

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
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.