I work on a company which has many Shop. Each shop has his own IP address :
SHOP 1 = 192.168.1.0/24, SHOP 2 = 192.168.2.0/24, SHOP 3 = 192.168.3.0/24, etc...
I have a number of Windows computers (between 1 and 9) on the same subnet (255.255.255.0) on each shop.
Each computer has a static IP address : 1st = 192.168.1.10, 2nd = 192.168.1.20, 3rd = 192.168.1.30, 4th = 192.168.1.40, etc.
The HQ of my company can deploy softs ONLY on the first computer on each shop (licences issue).
Here, we will try to install Xerox drivers on ALL windows computer on all shop.
I made 3 batch script :
The first, launched as the superadmin of the computer, install a new user with admin rights to install drivers
The second, launched as the new user, install Xerox drivers and set as default the printer.
The third, launched as the superadmin of the computer, try to install Xerox drivers on other computers of the same shop :
Loop over my 9 ip address (for /l %%G in (...) do (...)
For each IP address, test if it ping.
Do a ftp transfer between the computer 1 and the IP address (drivers packages + scripts)
PsExec64.exe to run the first script
PsExec64.exe to run the second script
The first and the second script works perfectly, we'll not speak about them.
Where I need help is on the thrid.
I try 3 scripts :
The first :
set subnet=192.168.1.
for /L %%G in (20, 10, 90) do (
ping -n 1 %subnet%%%G | findstr "TTL="
if %errorlevel%==0 (
echo Ping %subnet%%%G : OK >> log_ping_errorlevel.txt
) else (
echo Ping %subnet%%%G : KO >> log_ping_errorlevel.txt
)
)
Here the log_ping_errorlevel.txt with 2 computers on my subnet :
Ping 192.168.1.20 : OK
Ping 192.168.1.30 : OK
Ping 192.168.1.40 : OK
Ping 192.168.1.50 : OK
Ping 192.168.1.60 : OK
Ping 192.168.1.70 : OK
Ping 192.168.1.80 : OK
Ping 192.168.1.90 : OK`
I tried to surround %errorlevel% and 0 by simple quote but I get the same result.
Here an extract of the output if I run the batch in cmd window :
C:\Temp\Xerox_Install>(
ping -n 1 192.168.1.90 | findstr "TTL="
if '0'=='0' (echo "Ping 192.168.1.90 : OK" 1>>log_ping_errorlevel.txt ) el
se (echo "Ping 192.168.1.90 : KO" 1>>log_ping_errorlevel.txt )
)
It seems that the errorlevel is always = 0 in my script, IDK why.
The second :
set subnet=192.168.1.
for /L %%G in (20, 10, 90) do (
ping -n 1 %subnet%%%G && set pingtest=ok
if '%ping_test%'=='ok' (
echo Ping %subnet%%%G : OK >> log_ping_errorlevel.txt
) else (
echo Ping %subnet%%%G : KO >> log_ping_errorlevel.txt
)
)
Here the log_ping_set.txt with 2 computers on my subnet :
Ping 192.168.1.20 : OK
Ping 192.168.1.30 : OK
Ping 192.168.1.40 : OK
Ping 192.168.1.50 : OK
Ping 192.168.1.60 : OK
Ping 192.168.1.70 : OK
Ping 192.168.1.80 : OK
Ping 192.168.1.90 : OK`
I think the ping command result is always 0 then the setter pingtest can be executed.
The third :
Because I'm stuck with the ping command, I tried the if exist folder on remote computer :
set subnet=192.168.1.
for /L %%G in (20, 10, 90) do (
if exist \\%subnet%%%G\C$\Temp\ (
echo Remote folder reachable >> log_folder_reachable.txt
) else (
echo ERROR 404 - Remote folder not found >> log_folder_reachable.txt
)
)
Here the log_folder_reachable.txt with 2 computers on my subnet :
Remote folder reachable
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
ERROR 404 - Remote folder not found
It works BUT the if exist timeover is about 160 seconds and I don't want to wait for 160 seconds before going to the next computer...
Can someone help me with any method but not using external tools ?
You should read SO items about delayedexpansion.
if %errorlevel%==0 (
in the first script should be
if not errorlevel 1 (
[obviously, reverse the logical condition and remove the "not"]
if errorlevel 1 means "if errorlevel is 1 or greater than 1" and is interpreted on the run-time value of errorlevel.
Next:
ping -n 1 %subnet%%%G && set pingtest=ok
if '%ping_test%'=='ok' (
should be
set "ping_test="
ping -n 1 %subnet%%%G && set "ping_test=ok"
if defined ping_test (
Notes
you are setting pingtest in your ping command, then you are attempting to test ping_test
Even had the variablename been correct, the purpose for the quotes in an if statement is to combine the contents as a single string. Single-quotes don't cut the mustard, double-quotes are required.
With the code you have, ping_test once set will retain its value for the next loop, you need to clear it before theping.
The replacement code first sets the value of ping_test to nothing. The quotes delimit the variable name and value so that trailing spaces on the line are not included in the value assigned. The ping command then may set the value of ping_test to (ok, but any value other than nothing (ie something) is valid). The if defined command interprets the run-time value of the variable.
The third part - well, getting desperate, but no need to go this far as the changes I've outlined should solve the problem.
In regards to your first set of code where you said you tried to use delayed expansion it should look like this. Tested and works on my network.
#echo off
setlocal enabledelayedexpansion
set subnet=192.168.1.
for /L %%G in (20, 10, 90) do (
ping -n 1 %subnet%%%G | findstr "TTL="
if !errorlevel!==0 (
echo Ping %subnet%%%G : OK >> log_ping_errorlevel.txt
) else (
echo Ping %subnet%%%G : KO >> log_ping_errorlevel.txt
)
I am writing a windows script to read in a txt file with 9 columns of data
I want to write this data out to a csv file to be loaded into a database.
I have found that one column is sometimes blank, so I would like to enter code 'rdp'
another column has mostly numbers, but for reason some values are a '.' (presumably indicating value less than 1. I would like to change these values to '0'
my code
for /F %%b in (c:\ts_users\newfiles_list.txt) do (
for /F "tokens=1,2,3,4,5,6,7,8,9" %%i in (%%b) do (
echo %%i,%%j,%%k,%%l,%%m,!idle!,%%o %%p,%%q >>%%~nb.csv
)
)
this manages to read in the txt file, then write it out as a csv.
column k is sometimes empty, column n sometimes has a '.'
I have tried variations of
set var=rdp
if %%k="" then set !k:=!var!
which doesnt work, so I a little stumped (after googling internet for days)
current input
201401241611 USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME eu1ptsw002
201401241611 julie.noble rdp-tcp#9 3 Active 18 24/01/2014 14:24 eu1ptsw002
201401241611 svc.perfmon18 7 Disc 3 24/01/2014 14:15 eu1ptsw002
201401241611 reto.hofstetter 10 Disc 40 24/01/2014 10:57 eu1ptsw002
201401241611 lester.valentin 14 Disc 1:16 24/01/2014 11:53 eu1ptsw002
201401241611 philippe.bachmann 15 Disc 2 24/01/2014 12:45 eu1ptsw002
201401241611 patrik.soderlund rdp-tcp#2 21 Active 24 24/01/2014 07:42 eu1ptsw002
current output
201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME
201401241611,julie.noble,rdp-tcp#9,3,Active,,24/01/2014 14:24,eu1ptsw002
201401241611,svc.perfmon18,7,Disc,3,,14:15 eu1ptsw002,
201401241611,reto.hofstetter,10,Disc,40,,10:57 eu1ptsw002,
201401241611,lester.valentin,14,Disc,1:16,,11:53 eu1ptsw002,
201401241611,philippe.bachmann,15,Disc,2,,12:45 eu1ptsw002,
201401241611,patrik.soderlund,rdp-tcp#2,21,Active,,24/01/2014 07:42,eu1ptsw002
required output
201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME
201401241611,julie.noble,rdp-tcp#9,3,Active,18,24/01/2014 14:24,eu1ptsw002
201401241611,svc.perfmon18,rdp,7,Disc,3,24/01/2014 14:15,eu1ptsw002
201401241611,reto.hofstetter,rdp,10,Disc,40,24/01/2014 10:57,eu1ptsw002,
201401241611,lester.valentin,rdp,14,Disc,1:16,24/01/2014 11:53,eu1ptsw002
201401241611,philippe.bachmann,rdp,15,Disc,2,24/01/2014 12:45,eu1ptsw002
201401241611,patrik.soderlund,rdp-tcp#2,21,Active,24,24/01/2014 07:42,eu1ptsw002
#echo off &setlocal disableDelayedExpansion
for /f "delims=" %%a in (file) do (
set "line=%%~a"
setlocal enabledelayedexpansion
set "line=!line:,.,=,0,!"
set "line=!line:,,=,rdp,!"
echo(!line!
endlocal
)
I need to get certain fields from the output of the more +n command in Windows. The output of the more command is shown below. I need to extract certain field from this output.
Backup SAP L01_xyzabc_d01p001_PBW_ON_Daily Completed full 9/17/2013 6:00:05 PM 0:00 5:49 2360.00 1 0 0 254 100% 2013/09/17-135
Backup SAP L01_xyzabc_d01p001_PEC_ON_Daily Completed full 9/17/2013 7:00:05 PM 0:00 1:37 549.89 1 0 0 75 100% 2013/09/17-142
Backup SAP L01_xyzabc_d01p001_PPI_ON_Daily Completed full 9/17/2013 7:00:07 PM 0:00 2:04 656.00 1 0 0 104 100% 2013/09/17-143
Backup SAP L01_xyzabc_d01p001_PEP_ON_Daily Completed full 9/17/2013 8:00:05 PM 0:00 0:09 12.89 1 0 0 15 100% 2013/09/17-148
Backup SAP L01_xyzabc_d01p001_PDI_ON_Daily Completed full 9/17/2013 9:00:05 PM 0:00 0:07 5.63 1 0 0 14 100% 2013/09/17-156
Backup SAP L01_xyzabc_d01p001_PSM_ON_Daily Completed full 9/17/2013 10:00:06 P 0:00 0:22 92.08 1 0 0 21 100% 2013/09/17-161
Backup SAP L01_xyzabc_d01p001_PMD_ON_Daily Completed full 9/17/2013 11:00:06 P 0:00 0:09 9.53 1 0 0 26 100% 2013/09/17-169
Can this be done without installing anything or without using PowerShell?
-Louie
Try to use a for loop. This is a batch file version.
#echo off
for /f "tokens=1,2,3" %%a in ('more +n ...') do (
echo %%a %%b %%c
)
It would depend on the columns you wanted. You can see more info by typing help for on the command-line.
maybe someone can help me...
I have a list (containing also cyrillic letters) like this (channels.txt):
#EXTINF:-1,5 канал Россия
http://95.189.57.162:1234/udp/233.7.70.6:5000
#EXTINF:-0,ТВ3
http://95.189.57.161:1234/udp/233.7.70.7:5000
#EXTINF:-1,ТНТ
rtmp://95.189.54.166:1234/udp/233.7.70.8:5000
#EXTINF:-2,Disney Channel
mms://95.189.52.146:1234/udp/233.7.70.9:5000
#EXTINF:-1,49 Канал
http://95.189.51.163:1234/udp/233.7.70.11:5000
The line begining with #EXTINF: gives the name of a TV channel. Channels are:
5 канал Россия
ТВ3
ТНТ
Disney Channel
49 Канал
The next line is the link to that channel.
Which command or batch script could create a txt file for each channel of the list and put inside the corresponding link? For this example:
5 канал Россия.txt --> http://95.189.57.162:1234/udp/233.7.70.6:5000
ТВ3.txt --> http://95.189.57.161:1234/udp/233.7.70.7:5000
ТНТ.txt --> rtmp://95.189.54.166:1234/udp/233.7.70.8:5000
Disney Channel.txt --> mms://95.189.52.146:1234/udp/233.7.70.9:5000
49 Канал.txt --> http://95.189.51.163:1234/udp/233.7.70.11:5000
I would really appreciate any help!
Many thanks!
try this:
#ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION
FOR /f "tokens=2 delims=:" %%a IN ('chcp') DO SET /a CurrentCodePage=%%a 2>nul
CHCP 1251 >nul
FOR /f "tokens=1*delims=," %%a IN ('type file.txt') DO (
SET "link=%%a"
SET "channel=%%b"
IF DEFINED channel (SET "fname=!channel!"
) ELSE (ECHO !link!)>"!fname!.txt"
)
CHCP %currentCodePage% >nul
dir output is with code page 850:
06/29/2013 08:38 AM 48 49 ?????.txt
06/29/2013 08:38 AM 47 5 ????? ??????.txt
06/29/2013 08:38 AM 46 Disney Channel.txt
06/29/2013 08:38 AM 47 ??3.txt
06/29/2013 08:38 AM 47 ???.txt
dir output is with code page 1251:
06/29/2013 08:38 AM 48 49 Канал.txt
06/29/2013 08:38 AM 47 5 канал Россия.txt
06/29/2013 08:38 AM 46 Disney Channel.txt
06/29/2013 08:38 AM 47 ТВ3.txt
06/29/2013 08:38 AM 47 ТНТ.txt
For more information about cmd and code pages click here.
Is anyone aware of a library suitable for writing an image in .TMB format?
The .TMB format is suitable for printing logos from a Epson thermal receipt printer.
After about an hour or so of looking at binary data, I came to the following conclusion:
A *.TMB image is really just a serialized ESC/POS command to print a raster image.
Using the following command:
od -t a -v [YOUR_TMB_FILE] | head
we can view the binary data, as ASCII character data, in the beginning of the TMB file.
I had a file that looked something like this:
0000000 gs v 0 nul 5 nul P nul del del del del del del del del
0000020 del del del del del del del del del del del del del del del del
... snipped for brevity ...
According to the ESC/POS Programming Guide, the ASCII command to print a raster image is:
GS V 0
Hmm.. Interesting!
On a whim, I decided to convert 5 and P to their decimal equivalents, which are 53 and 80 respectively, the exact dimensions of my .TMB image (actually, its 80x53)!
Everything fell into place after this. The remainder of a .TMB file is just the binary image data.
Here is a one-off Python script I wrote to test my theory:
1 out = open('test.TMB', 'wb')
2
3 width = 80
4 height = 53
5
6 NUL = chr(0)
7 GS = chr(29)
8 V = chr(118)
9 ZERO = chr(48)
10
11 W = chr(width)
12 H = chr(height)
13
14 out.write(GS)
15 out.write(V)
16 out.write(ZERO)
17 out.write(NUL)
18
19 out.write(H)
20 out.write(NUL)
21 out.write(W)
22 out.write(NUL)
23
24 for y in range(0, height):
25 for x in range(0, width):
26 out.write(chr(127)) # looks like `del` in ASCII mode
27
28 out.close()