String Comparison In Batch Script
Jun 14, 2014
I am attempting to write a batch script that uses a program called Mailsend to send an email. The script then examines Mailsend's log output to determine if the email was successfully sent.
This is what I have so far:
Code: mailsend1.17b14.exe -to <snip personal info> -log temp.txt -attach test.txt.TailTail -1 temp.txt > temp2.txtDel temp.txtSet /p Message=<temp2.txtSet Message=%Message:~26%Set Cmess=Mail sent successfullyEcho %Message%Echo %Cmess%If "Message"=="Cmess" ( Echo Correct ) Else ( Echo Wrong )
Here is a rundown of what I am doing:
-The first line sends the email.
- The second and third use a program called Tail to delete all lines except the last one from the log file (the last line contains the output I'm looking for).
-The next 2 lines then assign the contents of the log file to a variable then truncate the first 26 characters (date and time info that I don't need).
-The next line creates a second variable that contains the desired output (i.e. "Mail sent successfully")
-The next two lines echos the contents of the variables.
-And finally, the last line compares the two variable and takes a particular action depending on whether the two variables are equal or not.
The comparison at the end is where I'm having problems. Every time I run the script, the last line I get printed on the screen is "Wrong" (i.e. the "Echo Wrong" command is executed meaning "Message" does not equal "Cmess"). This happens even when the email was sent successfully. I've tried various things and I haven't managed to get the "Echo Correct" command to ever execute, even when the output of the two Echo commands just before is exactly the same. I've even tried changing the "Set Cmess" line to:
Code: Set /p Cmess=<temp2.txt Set Cmess=%Cmess:~26%
And the output for the comparison is still "wrong". I can only think that there must be something wrong with how I structured the comparison.
How to get this script to work or script means of checking the log file for "Mail sent successfully"? This is what the log file contains if an email gets sent successfully:
Code: 07-Jun-2014 08:17:28.172: mailsend v@(#) mailsend v1.17b1407-Jun-2014 08:17:33.011: Mail sent successfully
View 6 Replies
Dec 19, 2013
I have lots of file with the date as part of the filename for example.
snapshot-2013-10-01.7z
snapshot-2013-01-10.7z
When I try to search for a file name using 2013-10 it return BOTH the above whilst it should only list the 1st entry.
Is there a trick to searching something like this ?
View 7 Replies
View Related
Jul 8, 2014
I accidentally set the file open of .bat files to Notepad. From a link in this forum (How to Restore Default File Extension Type Associations in Windows 8 and 8.1)was able to reset the registry back I think. The bat file not longer asks for notepad but instead opens "How do you want to open this file" and ask me to look for an app. The batch files still do not run.
View 8 Replies
View Related
Jun 10, 2013
I have: x4 .gif images, x14 .jpg images, and x5 .png images in my Code: C:UsersSampleUserDownloadsimg14
folder and want to move them to these desired locations via cmd.
Move the x4 .gif images to: Code: C:UsersSampleUserDownloadsimg14.gif
Move the x14 .jpg images to: Code: C:UsersSampleUserDownloadsimg14.jpg
Move the x5 .png images to: Code: C:UsersSampleUserDownloadsimg14.png
Any way I can go about this using a single command? Multiple commands will work just fine as well, as long it's not one too many commands.
OS: Windows 8 Enterprise x64
View 4 Replies
View Related
Aug 20, 2013
I'm trying to create a NETSH batch file that sets my TCP/IP settings to DHCP.
The line I want to use is:
netsh interface ipv4 set address name="My Custom Named Network" dhcp
If I run the global cmd prompt and paste this line, it works as intended. However, if I create a batch file with the same line, I get "The filename, directory name, or volume label syntax is incorrect".This is bugging me plenty.
View 9 Replies
View Related
Jan 3, 2014
I was browsing around and attempting to build a program with MS-DOS. I can't get the choice command to work in Windows 8, and I have browsed the internet searching for the problem and a solution. It seems that Microsoft has removed Choice from Windows 8 supported commands. Is there any way possible I can make this work? I also own a Windows XP desktop and I can make the codes on it, but I can't get them to run on Windows 8?
View 1 Replies
View Related
Feb 4, 2013
New Version (6/2/13)
- Changed name to Connec8
- Compiled as exe. This is for the sole purpose to force Administrator privileges on double click
- New icon
- Administrator privilege check on startup.
- Added option to restart the previous hotspot
- Implemented an easier way to enable Internet sharing
- Added blank lines for better readability
Download (dropbox) [URL] ....
Windows 8 is awesome. However it doesn't have the ability to create ad-hoc networks from Network and sharing center. The only way is to use netsh utility from CMD every time you want to start or stop your network. .
So I created a batch file to automate this process. All you have to do is to start it as administrator, follow the instructions and voila!. No need to open cmd again and again
This utility creates an adhoc network. You can use it for streaming Videos and Music or playing LAN games.
For Internet sharing aka Hotspot
Go to Network and Sharing Center –> Change adapter settings
Right click on the device which is connected to internet and select Proerties
Now, open Sharing tab, enable Allow other network users to connect through this computer’s Internet connection, and then choose the newly created ad-hoc connection from the list
View 1 Replies
View Related
Nov 9, 2012
Since Windows 8 is not creating System Restore points, apparently because I have a dual boot Windows 8 / Windows 7 setup, I'd like to schedule one every 3-4 days or so.
Is there any way to run system restore from Command line or batch file or Powershell? If so then I could schedule it to run when I want.
View 1 Replies
View Related