Archive for the ‘Scripting’ Category
Posted by jpluimers on 2021/07/21
On one of my Raspberry Pi boxes, somehow I could not access files over SFTP (SSH File Transfer Protocol) via FileZilla.
I would consistently get this error:
"Connection timed out after 20 seconds of inactivity"
Figuring the exact cause took a while.
TL;DR: SFTP uses an interactive non-login shell, then interprets the output from that shell. For that kind of shell, ensure few or none scripts run that output text.
These links finally got me to the cause
Read the rest of this entry »
Posted in *nix, *nix-tools, bash, bash, Communications Development, Conference Topics, Conferences, Development, Event, Internet protocol suite, Power User, Scripting, SFTP, Software Development, SSH, TCP | Leave a Comment »
Posted by jpluimers on 2021/07/15
[WayBack] How do I get the application exit code from a Windows command line? – Stack Overflow solutions below.
Note they ONLY work when nobody sets the ERRORLEVEL environment variable.
- – [WayBack]
-
something.exe
echo Exit Code is %errorlevel%
– [WayBack] Samuel Renkert
-
start /wait something.exe
echo %errorlevel%
– [WayBack] Gary
-
@echo off
my_nify_exe.exe
if %ERRORLEVEL% EQU 0 (
echo Success
) else (
echo Failure Reason Given is %errorlevel%
exit /b %errorlevel%
)
– [WayBack] Curtis Yallop
- It’s worth noting that .BAT and .CMD files operate differently.Reading https://ss64.com/nt/errorlevel.html it notes the following:
There is a key difference between the way .CMD and .BAT batch files set errorlevels:
An old .BAT batch script running the ‘new’ internal commands: APPEND, ASSOC, PATH, PROMPT, FTYPE and SET will only set ERRORLEVEL if an error occurs. So if you have two commands in the batch script and the first fails, the ERRORLEVEL will remain set even after the second command succeeds.
This can make debugging a problem BAT script more difficult, a CMD batch script is more consistent and will set ERRORLEVEL after every command that you run .
This was causing me no end of grief as I was executing successive commands, but the ERRORLEVEL would remain unchanged even in the event of a failure. – [WayBack] RockDoctor
–jeroen
Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/07/14
You can use:
IF "%~1" == "" GOTO MyLabel
to strip the outer set of quotes. In general, this is a more reliable method than using square brackets because it will work even if the variable has spaces in it.
Source: [WayBack] jamesdlin answering on [WayBack] windows – What is the proper way to test if a parameter is empty in a batch file? – Stack Overflow
The tilde (~) strips out double quotes from the command as per
C:\>help for | findstr "~"
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
%~ftzaI - expands %I to a DIR like output line
values. The %~ syntax is terminated by a valid FOR variable name.
–jeroen
Posted in Batch-Files, Development, Power User, Scripting, Software Development, Windows | Leave a Comment »
Posted by jpluimers on 2021/07/06
Even though RIVM twitter-care did not respond at all on my raised issue that the production environment leaded an acceptation environment URL, it did gain me some knowledge on their systems and the (then upcoming) European QR code systems.
[Archive.is] Jeroen Wiert Pluimers on Twitter: “Onhandig op de #CoronaCheck site van het @rivm de link hier (1) wijst nog naar de acceptatie omgeving en daar heb je authorisatie voor nodig. Zonder “.acc” werkt het ook niet: (2) Dit werkt wel: (3) CC @locuta… “
- web.acc.coronacheck.nl/nl/faq/1-6-welke-informatie-staat-in-mijn-qr-code/
- web.coronacheck.nl/nl/faq/1-6-welke-informatie-staat-in-mijn-qr-code/
- coronacheck.nl/nl/faq/1-6-welke-informatie-staat-in-mijn-qr-code/
The problem digging into it was that it only reproduces when inside the [Archive.is] Coronacheck Print Portaal after you have logged on via DigiD, so you cannot save it in the WayBack machine nor Archive.is.
This print portal isn’t a straightforward hierarchy of web-pages, but an actual Vue.js app that injects itself into [Wayback/Archive.is] nl-covid19-coronacheck-website/index.html at main · minvws/nl-covid19-coronacheck-website and dynamically changes the URL depending on the application state.
It also means that you cannot archive pages like coronacheck.nl/nl/print/vaccinatie-ophalen or coronacheck.nl/nl/print/keuze-papieren-bewijs as the Vue.js app will not understand state from those sub-URLs and go back to coronacheck.nl/nl/print/
The only other results of [Wayback] “acc.coronacheck.nl” – Google Search were:
Acceptance URLs in production
I had a hunch the CoronaCheck code would be open source, though finding it through the most obvious [Wayback] open source coronacheck app – Google Search failed. Since the web-site and app look very similar to the CoronaMelder web-site and app, I tried [Wayback] open source coronamelder app – Google Search and found the page with links: [Wayback] Colophon – Stop the spread of the coronavirus, download CoronaMelder.
Note that [Wayback] Open-Source Project Corona-Warn-App is a different beast. Though internationally available and released way earlier than the Dutch apps, the Dutch government has a huge ego (maybe even abbreviatable to Hugo) resulting in severe “not invented here” syndrome despite having had to be bailed out when “code black” happened in hospitals.
One thing that I learned is that there is one version of the code behind coronacheck.nl/nl/print/print-vaccinatie in the main branch of github.com/minvws/nl-covid19-coronacheck-website that has only acceptance URLs. They are in these locations:
Apparently, replacing these with production URLs is done during deployment, but I could not find the code that does it in the main repositories at [Wayback] github.com/minvws
European Corona/COVID-19 Green Pass QR certificate
One answer to my tweet was [Archive.is] Joel Haasnoot on Twitter: “gir.st/blog/greenpass.html… “ which provides more information on the European
These are the links I thought were interesting:
–jeroen
Read the rest of this entry »
Posted in Development, JavaScript/ECMAScript, Scripting, Software Development, Vue.js, Web Development | Leave a Comment »
Posted by jpluimers on 2021/06/22
Windows if full of undocumented gizmo’s, like find alternative for wc -l counting all lines in a file: [WayBack] File Line Count
Use FIND command to count file lines, store line count into a variable.
| Description: |
Running the FIND command with option /v and empty search string will find all lines
Running the FIND command with option /c will output the line count only.
The FOR command with option /f will parse the output, the line count in this case, and the set command put the line number into the cnt variable. |
| Script: |
1.
2.
3.
4.
|
set file=textfile.txt
set /a cnt=0
for /f %%a in ('type "%file%"^|find "" /v /c') do set /a cnt=%%a
echo %file% has %cnt% lines
|
|
| Script Output: |
Script Output |
textfile.txt has 50 lines
|
|
[WayBack] Stupid command-line trick: Counting the number of lines in stdin | The Old New Thing
Windows doesn’t come with wc,
but there’s a sneaky way to count the number of lines anyway:
some-command-that-generates-output | find /c /v ""
It is a special quirk of the find command
that the null string is treated as never matching.
The /v flag reverses the sense of the test,
so now it matches everything.
And the /c flag returns the count.
…
The reason dates back to the original MS-DOS
version of find.exe,
which according to the comments appears to have been written
in 1982.
And back then, pretty much all of MS-DOS was written in assembly
language.
…
Via: batch file line count – Google Search and [WayBack] windows – How to count no of lines in text file and store the value into a variable using batch script? – Stack Overflow
–jeroen
Posted in Batch-Files, Development, Scripting, Software Development, Windows Development | Leave a Comment »
Posted by jpluimers on 2021/06/16
On my list of things to play with: [WayBack] GitHub – jjjake/internetarchive: A Python and Command-Line Interface to Archive.org.
Via:
Related:
- [WayBack] The Internet Archive Python Library — Internet Archive item APIs 1.8.5 documentation
- [WayBack] Command-Line Interface — Internet Archive item APIs 1.8.5 documentation
- [WayBack] Quickstart — Internet Archive item APIs 1.8.5 documentation, including:
Configuring
Certain functionality of the internetarchive Python library requires your archive.org credentials. Your IA-S3 keys are required for uploading, searching, and modifying metadata, and your archive.org logged-in cookies are required for downloading access-restricted content and viewing your task history. To automatically create a config file with your archive.org credentials, you can use the ia command-line tool:
$ ia configure
Enter your archive.org credentials below to configure 'ia'.
Email address: user@example.com
Password:
Config saved to: /home/user/.config/ia.ini
Your config file will be saved to $HOME/.config/ia.ini, or $HOME/.ia if you do not have a .configdirectory in $HOME. Alternatively, you can specify your own path to save the config to via ia --config-file '~/.ia-custom-config' configure.
If you have a netc file with your archive.org credentials in it, you can simply run ia configure --netrc. Note that Python’s netrc library does not currently support passphrases, or passwords with spaces in them, and therefore not currently suported here.
–jeroen
Read the rest of this entry »
Posted in Development, Internet, InternetArchive, Power User, Python, Scripting, Software Development, WayBack machine | Leave a Comment »
Posted by jpluimers on 2021/06/10
One of the situations where setlocal enabledelayedexpansion comes on handy to replace \ with / which some unix based tools like better: [WayBack] string – Change backslash to forward slash in windows batch file – Stack Overflow
echo off
setlocal enabledelayedexpansion
for %%f IN ("C:\tools\workspace\*") DO (
set old=%%f
echo !old!
set new=!old:\=/!
echo !new!
echo.
)
Related, as it explains when the source and target replacements are in variables themselves: [WayBack] command line – String replacement in batch file – Stack Overflow, thanks Joey and Tom Warfield!
You can use the following little trick:
set word=table
set str="jump over the chair"
call set str=%%str:chair=%word%%%
echo %str%
The call there causes another layer of variable expansion, making it necessary to quote the original % signs but it all works out in the end.
…
Upvoting this answer because it works both ways, with the environment variable in either position, or in both the “before” and “after” positions:
set word=table
set str="jump over the chair"
call set str=%%str:chair=%word%%%
echo %str%
set word1=chair
set word2=desk
set str="jump over the chair"
call set str=%%str:%word1%=%word2%%%
echo %str%'
–jeroen
Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/05/25
Last week, I wrote about a bit of my command-line and scripting history at I wanted to know the loaded DLLs in a process like Process Explorer shows, but from the console: Sysinternals ListDLLs to the rescue.
Since information about VMS and DCL is harder to find nowadays, I saved some information in the wayback machine:
By now, there should be a good x86_64 version of OpenVMS, so this is also a reminder to self to see if that can run as a VM and is affordable enough to do some experimentation with.
–jeroen
Posted in Development, History, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/05/19
From my batch file library; note this PowerShell wrapper does not support stdin, but that is OK for me.
For Windows 10 and up, sort /unique works too and supports stdin.
:: note: does not work on stdin, unliqke sort which does support standard input
:: http://secretgeek.net/ps_duplicates
PowerShell Get-Content %1 ^| Sort-Object ^| Get-Unique
:: note that for Windoww 10 and up, there is a sort /unique switch, but Windows versions below it do not.
:: https://superuser.com/questions/1316317/is-there-a-windows-equivalent-to-the-unix-uniq
Related:
–jeroen
Posted in Batch-Files, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »