My target it to check whether a certificate (I have its exact name, in the example below it is "Dell") in any Windows computer is valid.
The way I think I can do it, is by taking the expiration date, and compare it with the current date.
So, first, I want to take the expiration date ("not after" field).
The way I did it:
certutil -verifystore Root Dell | findstr/n ^^ | findstr "^[6]:" | for /f "tokens=3-5 delims= " %f in ('more') do #echo %f %g %h
Output: 3/8/3020 8:47 PM
But note this is matching my regional date format. I need it to be generic- in a way it would work for all possible formats
Now, for any Windows computer I have the date.
Next step, is to get the current date with %date% variable, and calculate the seconds (?) difference between the two dates. With that result I could know whether the certificate is expired or not.
I can't find how to do so. Any advice?
Few notes:
No PowerShell
only 1 cmd command
The result of this 1 command should be the seconds difference of the 2 dates
Any other way to verify a certificate is acceptable. The way above is the only 1 I know
Related
oldest_year_month_temp=201602
NUM_PART_RETAIN=20
oldest_year_month=`date --date="$(oldest_year_month_temp +%Y%m) - $NUM_PART_RETAIN month" "+%Y%m"`
Date is not coming as expected.
One easy way to do it would be to simply append a 01 to your input of yymm to provide a format date -d could read as the starting date, then simply subtract 20 months and output the resulting date in %y%m format. For example, if you provide the date 9910 (Oct. 1999), you can do:
$ date -d "991001 - 20 months" +%y%m
9802
Which returns Feb. 1998 (20 months earlier)
(note: the $ above just indicates a command by a normal user as opposed to # indicating a command by the super user (e.g. root))
Inside the $(...) there must be a command, e.g. $(date ...).
This should have been obvious from the error message you got, which was probably oldest_year_month_temp: no such command.
When reading from a variable, you must write a $ before its name.
If this has been asked here before, I'm not finding it.
I think I know a way around my actual problem, but it'd get a bit unwieldy; so this is more of a puzzle, I guess.
I want to set 12 variables:
set 01=01 - January
set 02=02 - February
set 03=03 - March
set 04=04 - April
set 05=05 - May
set 06=06 - June
set 07=07 - July
set 08=08 - August
set 09=09 - September
set 10=10 - October
set 11=11 - November
set 12=12 - December
If I use a CMD file to ask what's contained in %01%, I'm returned the name of the CMD file (which is always %0) plus the number 1. For %10% through %12%, I receive the content of %1, which in my case so far has been empty, plus the second digit of the variable name.
I'm moving files based on date to a storage server. The files are named "2015-01-01 Blah, Blah, Blah.txt", for instance. I can use code obtained here elsewhere to find out the year as token1 and the month as token2.
The storage destination has a folder for 2015, and inside that are subfolders, "01 - January", "02 - February", and so on.
I can always do a thorough "if token2=" each freaking month, for every single file, but I'm wondering whether there's a way to streamline the logic: Move %1 token1\token2, where 01 is expanded to "01 - January", without needing to IF my way through each month.
Code to start from:
#echo off
set 01=01 - January
set 02=02 - February
set 03=03 - March
set 04=04 - April
set 05=05 - May
set 06=06 - June
set 07=07 - July
set 08=08 - August
set 09=09 - September
set 10=10 - October
set 11=11 - November
set 12=12 - December
:: set /p cr_mo= "Pick a month, any month! "
:: echo CR_Mo=%CR_Mo%
:: echo Destination folder: %CR_Mo%
echo 01=%01%
echo 02=%02%
echo 03=%03%
echo 04=%04%
echo 05=%05%
echo 06=%06%
echo 07=%07%
echo 08=%08%
echo 09=%09%
echo 10=%10%
echo 11=%11%
echo 12=%12%
easiest way is to use delayed expansion:
#echo off
setlocal enabledelayedexpansion
set 01=01 - January
echo 01=!01!
What does /p stand for in set /p=? I know that / enables a switch, and I'm fairly sure that I know /a is for arithmetic. I've heard numerous rumours, some saying /p is for prompt, others stating it stands for print. The only reason I slightly doubt it is prompt is because in many cases it does not ask for a prompt, yet prints on the screen, such as
<nul set /p=This will not generate a new line
But what I want to know is: Do we really know what it stands for?
The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty.
Two ways I've used it... first:
SET /P variable=
When batch file reaches this point (when left blank) it will halt and wait for user input. Input then becomes variable.
And second:
SET /P variable=<%temp%\filename.txt
Will set variable to contents (the first line) of the txt file. This method won't work unless the /P is included. Both tested on Windows 8.1 Pro, but it's the same on 7 and 10.
For future reference, you can get help for any command by using the /? switch, which should explain what switches do what.
According to the set /? screen, the format for set /p is SET /P variable=[promptString] which would indicate that the p in /p is "prompt." It just prints in your example because <nul passes in a nul character which immediately ends the prompt so it just acts like it's printing. It's still technically prompting for input, it's just immediately receiving it.
NOTE: The answers below this point are for a previous version of the question.
/L in for /L generates a List of numbers.
From ping /?:
Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
[-r count] [-s count] [[-j host-list] | [-k host-list]]
[-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name
Options:
-t Ping the specified host until stopped.
To see statistics and continue - type Control-Break;
To stop - type Control-C.
-a Resolve addresses to hostnames.
-n count Number of echo requests to send.
-l size Send buffer size.
-f Set Don't Fragment flag in packet (IPv4-only).
-i TTL Time To Live.
-v TOS Type Of Service (IPv4-only. This setting has been deprecated
and has no effect on the type of service field in the IP Header).
-r count Record route for count hops (IPv4-only).
-s count Timestamp for count hops (IPv4-only).
-j host-list Loose source route along host-list (IPv4-only).
-k host-list Strict source route along host-list (IPv4-only).
-w timeout Timeout in milliseconds to wait for each reply.
-R Use routing header to test reverse route also (IPv6-only).
-S srcaddr Source address to use.
-4 Force using IPv4.
-6 Force using IPv6.
I am aware that one can print batch time up to the centisecond with #echo %time%. Is there a similar command to get milliseconds as well?
There is a resource kit utility named Timethis that provides up to the millisecond time measurements :
TimeThis : Command Line : dir
TimeThis : Start Time : Wed Oct 24 12:49:56 2012
TimeThis : End Time : Wed Oct 24 12:49:56 2012
TimeThis : Elapsed Time : 00:00:00.093
Use wmic os get LocalDateTime. That's also the reliable way to get locale-independent date and time
for /F "usebackq tokens=2 delims==" %%i in (
`wmic os get LocalDateTime /VALUE`
) do #set ctime=%%i
echo milliseconds: %ctime:~15,3%
(Edit: doh, didn't notice that this has the windows tag. Leaving the answer here in case anyone else clicked on this for Linux)
If you are asking to time the execution length of a program or script, precede the command with time, for example:
time ls -R
and this will give you execution time in milliseconds:
real 0m0.667s
user 0m0.000s
sys 0m0.144s
If you are asking for the current date and time:
Take a look at:
man date
For example,
date +"%X %N"
This will give you the current time in Hour:Minutes:Seconds and then the Nanoseconds
Hope this answers your question
Gnu gdate can make this very simple; try the code below in a batch file, for instance. I use it to create unique filenames for batch processes invoked in command windows, and on my system under Windows 7 it's evident that, at least in a command window, two immediately successive uses of gdate never give identical results.
gdate +"%%Y%%m%%d%%H%%M%%S%%N"
gdate +"%%Y%%m%%d%%H%%M%%S%%N"
set i=
set T=
for /f %%i in ('gdate +%%Y%%m%%d%%H%%M%%S%%N') do set UniqueTime=%%i
echo %UniqueTime%
But I actually use something more like the line below, discarding the last five digits because for my purposes they never seem to matter: the preceding part is always unique. This lets the unique file names be shorter.
gdate +"%%Y%%m%%d%%H%%M%%S%%N" | sed "s/.....$//"
Pretty obviously, the same expression works under Linux, so one can also use it there.
ptime utility is "5ms or better" accurate
ptime echo hallo
ptime 1.0 for Win32, Freeware - http://www.pc-tools.net/
Copyright(C) 2002, Jem Berkes <jberkes#pc-tools.net>
=== echo hallo ===
hallo
Execution time: 0.022 s
I have a strange (don't ask) need to see a few examples of a Win XP cmd shell DIR command for lots (some) of different localized versions of windows (eg. French, Spanish, etc).
The specific command I need is (note that this command is important... if you don't bother to use this command then don't bother to respond):
dir /4 /-c /t:a /n /a:-d-h-s
I know it's a crazy hope but I'm hoping to be able to chop/parse the output regardless of localization.
Probably not what you want to hear but we found all sorts of problems in relying on behavior in different localizations of Windows.
We had a cmd file which worked fine in US English but when we sent it for localization, they found all sorts of issues, and we have to support about 23 different versions.
In the end, it was easier to write (actual C) code to get the information via Win32 and output it in the format we wanted. This removed reliance on specific localization formats and configuration issues (some commands output differently not just based on locale but also on user configuration).
My advice: find a different way of doing this.
Polish windows Vista outputs:
C:\Users\Karol>dir /4 /-c /t:a /n /a:-d-h-s
Wolumin w stacji C to OS
Numer seryjny woluminu: 3EC1-6B83
Katalog: C:\Users\Karol
2009-12-10 21:19 2263 intlname.ols
2009-07-23 21:17 1480 laptop_to_epia.ppk
2009-07-23 21:17 466 laptop_to_epia.pub
2010-01-31 09:49 10392 _viminfo
4 plik(ów) 14601 bajtów
0 katalog(ów) 10880864256 bajtów wolnych
Here's the output for Korean XP:
C µå¶óÀ̺êÀÇ º¼·ý¿¡´Â À̸§ÀÌ ¾ø½À´Ï´Ù.
º¼·ý ÀÏ·Ã ¹øÈ£: 7C33-7DCE
C:\WINDOWS\system32 µð·ºÅ͸®
2009-02-02 ¿ÀÈÄ 11:39 1697 $winnt$.inf
2008-02-19 ¿ÀÈÄ 09:07 2151 12520437.cpx
2008-02-19 ¿ÀÈÄ 09:07 2233 12520850.cpx
2008-02-19 ¿ÀÈÄ 09:06 100352 6to4svc.dll
2008-02-19 ¿ÀÈÄ 08:47 1460 a15.tbl
(seem to have lost the unicode during transfer... but for my purposes that's ok).
Sure... it's the wrong way... but needs must/devil drives. The underlying problem is that the machine the command runs on cannot be modified/relied upon. The parsing/chopping is pretty minor (pull out a filename, file size and the creation date). The good news is that the filename is guaranteed to not include any spaces. Which means the last 2 fields of a split() are the filename and size and the first N fields are the date (note I don't need the date as a date, just a string is fine). Trickiness may be involve ensuring unicode moves around correctly (unlike in the Korean example).