Archive for the ‘Scripting’ Category
Posted by jpluimers on 2016/01/13
Many sites giving your public IP address return a web page with a bloat of html. From the command-line, you are usually only interested in the IP-address itself. Few services return exactly that.
Below are command-line examples to provide the public IP address mostly from a *nix perspective. Usually you can get similar commands to work with Windows binaries for wget and Windows binaries for curl.
In the end, I’ve opted for commands in this format, as I think akamai will last longer than the other sites (but does not include an end-of-line in the http result hence the echo on Mac/*nix):
I’ve not tried aria2 yet, but might provide commands for that in the future.
These are the Linux permutations for akamai:
curl whatismyip.akamai.com && echo
curl ipv4.whatismyip.akamai.com && echo
curl ipv6.whatismyip.akamai.com && echo
curl ipv4.whatismyip.akamai.com && echo && curl ipv6.whatismyip.akamai.com && echo
The last two are convenient when you have both IPv4 and IPv6 configured on “the outside”.
You can replace curl with wget -q -O – (which outputs to stdout) for each command. You can even ommit the http:// (as that is the default protocol for both curl and wget).
Read the rest of this entry »
Posted in *nix, *nix-tools, Apple, bash, bash, Batch-Files, cURL, Development, Linux, Mac, Mac OS X / OS X / MacOS, Mac OS X 10.4 Tiger, Mac OS X 10.5 Leopard, Mac OS X 10.6 Snow Leopard, Mac OS X 10.7 Lion, MacBook, MacBook Retina, MacBook-Air, MacBook-Pro, MacMini, OS X 10.10 Yosemite, OS X 10.8 Mountain Lion, OS X 10.9 Mavericks, Power User, Scripting, Software Development, SuSE Linux, wget | Leave a Comment »
Posted by jpluimers on 2016/01/06
I had to verify the rights on some parts of the registry were the same for a lot of machines. So I used AccessChk by SysInternals.
If there were difference, my plan was to use REGINI to fix them.
It appears that AccessCheck does not show the permissions for objects within the specified path, not for the path itself.
As I observed that
accesschk -k hklm\software\Microsoft\Windows\Shell
does not reveal results.
But
accesschk -k hklm\software\Microsoft\Windows
shows:
Read the rest of this entry »
Posted in Batch-Files, Development, Power User, Scripting, Software Development, Windows, Windows 7, Windows 8, Windows 8.1, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2 | Leave a Comment »
Posted by jpluimers on 2016/01/05
DiskMgmt.msc does not allow you to delete EFI partitions.
I tried with WMI first.
wmic has a nice assoc mode that allows you to find associated classes like the logical drive association to physical partitions.
But lets start simple: physical partitions and logical drives.
C:\temp>wmic partition get DeviceID, DiskIndex, Index, Type
DeviceID DiskIndex Index Type
Disk #1, Partition #0 1 0 GPT: System
Disk #0, Partition #0 0 0 Installable File System
C:\temp>wmic logicaldisk get Caption, DriveType, FileSystem, ProviderName, VolumeName
Caption DriveType FileSystem ProviderName VolumeName
C: 3 NTFS
D: 5
These Associations:
They can be hard to use.
LogicalDisks are bound to a Partition, but a Partition does not need to have a Logical Disk.
I wanted the other way around: finding partitions not having a LogicalDisk association. But that does not seem to be possible with WMI at all.
Heck, detecting EFI partitions with WMI seems to be impossible.
DiskPart
Even though there needs to be a 15 second delay between DiskPart invocations:
you must allow at least 15 seconds between each script for a complete shutdown of the previous execution before running the DiskPart command again in successive scripts
it seems to be the only way to go.
But it is hard, as there seems to be no way to convert from volume (which lists the EFI partition as ESP), to disk+partition.
So a way to automate what How to delete a protected EFI disk partition with Windows 7 or 8 | WinAbility Software describes seems impossible.
Any thoughts on that?
This is what I have done so far
- diskpart
- list volume
- now note the volume that has ESP
- list disk
- for each disk
- select disk #
- list disk
- to confirm you selected the correct disk
- list partition
- select partiton #
- list partition
- to confirm you selected the correct partition
- list volume
- to confirm the partition indeeds corresponds to the EFI volume
- delete partition override
- list volume
- list partition
- for each partition coming after the EFI partition
- select partition #
- list partition
- to confirm
- delete partition
- list partition
- to confirm
Now you can create a new partition on the disk.
–jeroen
via:
Posted in Batch-Files, Development, Power User, Scripting, Software Development, Windows | Leave a Comment »
Posted by jpluimers on 2015/12/30
This is what I needed:
:: http://www.windows-commandline.com/disable-screensaver-registry-settings/
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 0 /f
And this one to verify the current settings:
:: http://www.windows-commandline.com/disable-screensaver-registry-settings/
:: possible names
:: ScreenSaveActive
:: ScreenSaveTimeOut
:: ScreenSaverIsSecure
reg query "HKEY_CURRENT_USER\Control Panel\Desktop" | findstr /I /C:"ScreenSave"
–jeroen
via:
Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2015/12/29
I needed to compare the local group memberships on a few systems.
I knew there is the distinction between
- net group (which despite documentation requires /domain as it does not support local groups: you get a nice NET HELPMSG 3515 error) and
- net localgroup (which can either run locally or with /domain).
So I came up with this batch file thanks to Command Line Kung Fu:
:: http://blog.commandlinekungfu.com/2009/06/episode-43-users-groups.html
for /F "skip=4 delims=*" %%g in ('net localgroup ^| find /v "The command completed successfully"') do @net localgroup "%%g"
It can be done in PowerShell too, but is more work.
Based on that and Beyond Compare I created some diff scripts.
–jeroen
via:
Posted in Batch-Files, Development, Scripting, Software Development | 1 Comment »
Posted by jpluimers on 2015/12/18
Interesting:
For codesign verification:
find /Applications -d 1 -name "*.app" -exec codesign --verify --verbose {} \;
For system policy assessment:
find /Applications -d 1 -name "*.app" -exec spctl --assess --verbose {} \;
–jeroen
Source: How to verify app signatures in OS X | MacIssues
Posted in Apple, bash, Development, Mac, Mac OS X / OS X / MacOS, Mac OS X 10.6 Snow Leopard, MacBook, MacBook Retina, MacBook-Air, MacBook-Pro, MacMini, OS X 10.10 Yosemite, OS X 10.8 Mountain Lion, OS X 10.9 Mavericks, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2015/12/03
I wish I had seen this years ago, as I’ve always had a hate-hate relationship with many shells on many OS-es.
I’ve included the ToC; read the rest of BashPitfalls: common errors that Bash programmers make – Greg’s Wiki back-to-back. It’s worth it, really.
Bash Pitfalls
This page shows common errors that Bash programmers make. These examples are all flawed in some way.
You will save yourself from many of these pitfalls if you simply always use quotes and never use WordSplitting for any reason! Word splitting is a broken legacy misfeature inherited from the Bourne shell that’s stuck on by default if you don’t quote expansions. The vast majority of pitfalls are in some way related to unquoted expansions, and the ensuing word splitting and globbing that result.
Posted in bash, Development, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2015/10/29
On a system where I just added a new E: drive, it was indeed available as
wmic logicaldisk where drivetype=3 get caption,filesystem,drivetype,providername,volumename
would output:
Caption DriveType FileSystem ProviderName VolumeName
C: 3 NTFS
D: 3 NTFS
E: 3 NTFS
But it would not list as an administrative share since
net share
would give:
Share name Resource Remark
-------------------------------------------------------------------------------
IPC$ Remote IPC
ADMIN$ C:\WINDOWS Remote Admin
D$ D:\ Default share
C$ C:\ Default share
The command completed successfully.
I wonder why the E$ drive was not visible. If anyone knows a better solution than a reboot, please let me know.
This was after the reboot:
Share name Resource Remark
-------------------------------------------------------------------------------
IPC$ Remote IPC
ADMIN$ C:\WINDOWS Remote Admin
D$ D:\ Default share
E$ E:\ Default share
C$ C:\ Default share
The command completed successfully.
–jeroen
via:
Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2015/10/15
LOL:
The if syntax of your script was a bit…well, iffy.
Indeed it is:
#!/bin/bash
#toggle AppleShowAllFiles
current_value=$(defaults read com.apple.finder AppleShowAllFiles)
if [ $current_value = "TRUE" ]
then
defaults write com.apple.finder AppleShowAllFiles FALSE
else
defaults write com.apple.finder AppleShowAllFiles TRUE
fi
killall Finder
Even the alternative if statement is:
if [[ $(defaults read com.apple.finder AppleShowAllFiles) == TRUE ]]
–jeroen
via osx – Toggle AppleShowAllFiles with a simple bash script? – Stack Overflow.
Posted in Apple, bash, Development, Mac, Mac OS X / OS X / MacOS, Mac OS X 10.4 Tiger, Mac OS X 10.5 Leopard, Mac OS X 10.6 Snow Leopard, Mac OS X 10.7 Lion, OS X 10.10 Yosemite, OS X 10.8 Mountain Lion, OS X 10.9 Mavericks, Power User, Scripting, Software Development | Leave a Comment »