Determine values of several system variables in the terminal in a Mac - bash

I'm on a Mac. In the terminal, how would you figure out each of the following values?
Word size (64 bit vs. 32 bit)
L1/L2 cache size
Determine how much memory is being used (like df, but for RAM)
Thanks! I know you can find these in Activity Monitor, System Profiler etc. but I am trying to boost my knowledge of the terminal, and UNIX.

System Profiler is a GUI wrapper around /usr/sbin/system_profiler.
mress:10008 Z$ system_profiler -listDataTypes
Available Datatypes:
SPHardwareDataType
SPNetworkDataType
SPSoftwareDataType
SPParallelATADataType
SPAudioDataType
SPBluetoothDataType
SPCardReaderDataType
SPDiagnosticsDataType
SPDiscBurningDataType
SPEthernetDataType
SPFibreChannelDataType
SPFireWireDataType
SPDisplaysDataType
SPHardwareRAIDDataType
SPMemoryDataType
SPPCIDataType
SPParallelSCSIDataType
SPPowerDataType
SPPrintersDataType
SPSASDataType
SPSerialATADataType
SPUSBDataType
SPAirPortDataType
SPFirewallDataType
SPNetworkLocationDataType
SPModemDataType
SPNetworkVolumeDataType
SPWWANDataType
SPApplicationsDataType
SPDeveloperToolsDataType
SPExtensionsDataType
SPFontsDataType
SPFrameworksDataType
SPLogsDataType
SPManagedClientDataType
SPPrefPaneDataType
SPStartupItemDataType
SPSyncServicesDataType
SPUniversalAccessDataType
mress:10009 Z$ system_profiler SPHardwareDataType
Hardware:
Hardware Overview:
Model Name: iMac
Model Identifier: iMac10,1
Processor Name: Intel Core 2 Duo
Processor Speed: 3.33 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 6 MB
Memory: 16 GB
Bus Speed: 1.33 GHz
Boot ROM Version: IM101.00CC.B00
SMC Version (system): 1.52f9
Serial Number (system): QP0241DXB9S
Hardware UUID: 01C6B9E9-B0CB-5249-8AC7-069A3E44A188
You can also get some useful information from /usr/sbin/sysctl (try sysctl -a).
mress:10014 Z$ sudo sysctl -a | grep cache
Password:
hw.cachelinesize = 64
hw.l1icachesize = 32768
hw.l1dcachesize = 32768
hw.l2cachesize = 6291456
kern.flush_cache_on_write: 0
vfs.generic.nfs.client.access_cache_timeout: 60
vfs.generic.nfs.server.reqcache_size: 64
net.inet.ip.rtmaxcache: 128
net.inet6.ip6.rtmaxcache: 128
hw.cacheconfig: 2 1 2 0 0 0 0 0 0 0
hw.cachesize: 17179869184 32768 6291456 0 0 0 0 0 0 0
hw.cachelinesize: 64
hw.l1icachesize: 32768
hw.l1dcachesize: 32768
hw.l2cachesize: 6291456
machdep.cpu.cache.linesize: 64
machdep.cpu.cache.L2_associativity: 8
machdep.cpu.cache.size: 6144

Related

Is there any specific way to extract SSD name without "/"?

In my current system, I have 3 SSDs, sda, sdb and sdc. The OS is installed in sdc.
I am trying to extract the SSDs without the OS installed in it. So, this command
echo $(eval $(lsblk -oMOUNTPOINT,PKNAME -P | grep 'MOUNTPOINT="/"'); echo $PKNAME | sed 's/[0-9]*$//')
returns sdc.
But if I want the drive without OS, how should I modify the above command?
grep 'MOUNTPOINT!="/"' doesn't return anything.
The bash script provided by Renaud works as expected on systems with raw drives. In case, if the system has LVM partitions then it returns only dm-1.
How to handle this case? To get the correct SSD name on either raw or LVM systems?
On the LVM system, lsblk returns. The expected output is sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.8T 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 1.8T 0 part
├─ubuntu--vg-ubuntu--lv-real
│ 253:1 0 880G 0 lvm
│ ├─ubuntu--vg-ubuntu--lv 253:2 0 880G 0 lvm /
│ └─ubuntu--vg-clean 253:4 0 880G 0 lvm
└─ubuntu--vg-clean-cow 253:3 0 400G 0 lvm
└─ubuntu--vg-clean 253:4 0 880G 0 lvm
sdb 8:16 0 1.8T 0 disk
On the raw drive, lsblk returns
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223.6G 0 disk
sdb 8:16 0 465.8G 0 disk
├─sdb1 8:17 0 2G 0 part
└─sdb2 8:18 0 463.8G 0 part
sdc 8:32 0 232.9G 0 disk
├─sdc1 8:33 0 156M 0 part /boot/efi
├─sdc2 8:34 0 26.7G 0 part /boot
├─sdc3 8:35 0 182.7G 0 part /
└─sdc4 8:36 0 23.4G 0 part [SWAP]
Here the expected output is sda or sdc.
grep has a -v option to print only non-matching lines. So:
lsblk -oMOUNTPOINT,PKNAME -P | grep -v 'MOUNTPOINT="/"'
should exclude this drive. But note that if you have more than one other drive the rest of your script will not work as you would like. Only the last drive will be considered because it overrides the others. A loop would probably be closer to your needs:
while IFS= read -r line; do
eval "$line"
sed 's/[0-9]*$//' <<< "$PKNAME"
done < <(lsblk -oMOUNTPOINT,PKNAME -P | grep -v 'MOUNTPOINT="/"')

Windows Volume without a Partition

Background:
I'm working on a powershell script to automate installation from a USB stick via WinPE. Because the target systems have several drives, each possibly having a couple partitions, Windows quickly runs out of drive letters. Part of my script unassigns all drive letters, then reassigns only the necessary disks. Right now, I assign hard-coded letters to certain partitions, but I've run into a problem with one of the letters not being unassigned.
The issue is that I somehow have a volume with an assigned drive letter, yet there's apparently no underlying partition, and since Remove-PartitionAccessPath requires a partition object, there's no way to do it from powershell (without resorting to diskpart).
Here's the output of diskpart - you can see the selected disk has no partitions, yet somehow has a volume:
Microsoft DiskPart version 10.0.15063.0
Copyright (C) Microsoft Corporation.
On computer: MININT-6GI0UNM
DISKPART> list disk
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 5589 GB 0 B *
Disk 1 Online 5589 GB 0 B *
Disk 2 Online 5589 GB 0 B *
Disk 3 Online 5589 GB 0 B *
Disk 4 Online 5589 GB 0 B *
Disk 5 Online 5589 GB 0 B *
Disk 6 Online 5589 GB 0 B *
Disk 7 Online 5589 GB 0 B *
Disk 8 Online 5589 GB 0 B *
Disk 9 Online 5589 GB 0 B *
Disk 10 Online 5589 GB 0 B *
Disk 11 Online 5589 GB 0 B *
Disk 12 Online 447 GB 0 B *
Disk 13 Online 447 GB 0 B *
Disk 14 Online 232 GB 0 B *
Disk 15 Online 29 GB 29 GB
Disk 16 Online 28 GB 0 B *
DISKPART> sel disk 15
Disk 15 is now the selected disk.
DISKPART> list part
There are no partitions on this disk to show.
DISKPART> detail disk
ATA Hypervisor USB Device
Disk ID: E0623CE6
Type : USB
Status : Online
Path : 0
Target : 0
LUN ID : 0
Location Path : UNAVAILABLE
Current Read-only State : No
Read-only : No
Boot Disk : No
Pagefile Disk : No
Hibernation File Disk : No
Crashdump Disk : No
Clustered Disk : No
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 20 E Removable 0 B Unusable
DISKPART>
Here's what happens when I try to remove the letter from powershell:
PS X:\sources> Get-Volume -DriveLetter E | Remove-PartitionAccessPath -AccessPath "E:"
Remove-PartitionAccessPath : The input object cannot be bound to any parameters for the command either because the
command does not take pipeline input or the input and its properties do not match any of the parameters that take
pipeline input.
At line:1 char:29
+ ... t-Volume -DriveLetter E | Remove-PartitionAccessPath -AccessPath "E:"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_Volume (Ob...rosoft/Wind...):PSObject) [Remove-PartitionAccessPat
h], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Remove-PartitionAccessPath
PS X:\sources> Get-Volume -DriveLetter E | fl *
OperationalStatus : Unknown
HealthStatus : Healthy
DriveType : Removable
FileSystemType : Unknown
DedupMode : NotAvailable
ObjectId : {1}\\MININT-6GI0UNM\root/Microsoft/Windows/Storage/Providers_v2\WSP_Volume.ObjectId="{63585070-
3cd2-11e7-b877-806e6f6e6963}:VO:\\?\Volume{635850c4-3cd2-11e7-b877-806e6f6e6963}\"
PassThroughClass :
PassThroughIds :
PassThroughNamespace :
PassThroughServer :
UniqueId : \\?\Volume{635850c4-3cd2-11e7-b877-806e6f6e6963}\
AllocationUnitSize : 0
DriveLetter : E
FileSystem :
FileSystemLabel :
Path : \\?\Volume{635850c4-3cd2-11e7-b877-806e6f6e6963}\
Size : 0
SizeRemaining : 0
PSComputerName :
CimClass : ROOT/Microsoft/Windows/Storage:MSFT_Volume
CimInstanceProperties : {ObjectId, PassThroughClass, PassThroughIds, PassThroughNamespace...}
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties
PS X:\sources> Get-Volume -DriveLetter E | Get-Partition
PS X:\sources> $null -eq (Get-Volume -DriveLetter E | Get-Partition)
True
Powershell version table:
PS X:\sources> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.15063.0
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.15063.0
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
I can try to get more details about the contents of the disk in question if necessary.
What could be causing this? Is there a powershell workaround?
Note: I realize it would probably be better to have Windows pick drive letters instead of hard-coding them, but I'm still curious about the mysterious volume.
Try this:
Get-Volume -Drive 'E' | Get-Partition | Remove-PartitionAccessPath -AccessPath 'E:\'
Reference: https://blogs.technet.microsoft.com/heyscriptingguy/2015/12/07/powertip-use-powershell-to-remove-drive-letter/

modprobe error: could not insert 'ext3': Device or resource busy

I'm working towards understanding the ext3 file system. i have added printk statements into the files inside kernel source files of ext3, to see how things get executed by watching the kernel buffer messages (dmesg). I have followed the steps given in this link: https://askubuntu.com/questions/168279/how-do-i-build-a-single-in-tree-kernel-module . i am using following commands to build ext3 as a module to experiment on it by loading and unloading it using modprobe.
The commands are:
cd $HOME/linux-3.12.36/
make oldconfig # copy old .config to ./
vi .config # i have made CONFIG_EXT3_FS=m
make prepare
make modules_prepare
make SUBDIRS=scripts/mod
make SUBDIRS=fs/ext3 modules
# Then I created 'ext3' directory in /lib/modules/3.12.36/kernel/fs, which was not there earlier.
cp fs/ext3/ext3.ko /lib/modules/3.12.36/kernel/fs/ext3/
depmod
modprobe ext3
all executes ok... except the last statement which gives the error:
modprobe: ERROR: could not insert 'ext3': Device or resource busy.
my lsmod result in case helpfull:
Module Size Used by
ums_realtek 18045 0
usb_storage 62230 1 ums_realtek
auth_rpcgss 59261 0
rfcomm 69078 0
bnep 19704 2
bluetooth 372312 10 bnep,rfcomm
sunrpc 284347 2 auth_rpcgss
arc4 12608 2
iwldvm 236564 0
snd_hda_codec_hdmi 41149 1
snd_hda_codec_realtek 56979 1
mac80211 607387 1 iwldvm
snd_hda_intel 56546 3
snd_hda_codec 192906 3 snd_hda_codec_realtek,snd_hda_codec_hdmi,snd_hda_intel
i915 711131 8
snd_hwdep 13602 1 snd_hda_codec
snd_pcm 102042 3 snd_hda_codec_hdmi,snd_hda_codec,snd_hda_intel
iwlwifi 165575 1 iwldvm
snd_page_alloc 18710 2 snd_pcm,snd_hda_intel
snd_seq_midi 13324 0
snd_seq_midi_event 14899 1 snd_seq_midi
parport_pc 32741 0
snd_rawmidi 30144 1 snd_seq_midi
uvcvideo 80843 0
snd_seq 61560 2 snd_seq_midi_event,snd_seq_midi
snd_seq_device 14497 3 snd_seq,snd_rawmidi,snd_seq_midi
videobuf2_vmalloc 13216 1 uvcvideo
snd_timer 29427 2 snd_pcm,snd_seq
videobuf2_memops 13362 1 videobuf2_vmalloc
cfg80211 483503 3 iwlwifi,mac80211,iwldvm
videobuf2_core 40625 1 uvcvideo
ppdev 17635 0
snd 69274 17 snd_hda_codec_realtek,snd_hwdep,snd_timer,snd_hda_codec_hdmi,snd_pcm,snd_seq,snd_rawmidi,snd_hda_codec,snd_hda_intel,snd_seq_device,snd_seq_midi
intel_powerclamp 14727 0
drm_kms_helper 52758 1 i915
videodev 134093 2 uvcvideo,videobuf2_core
drm 297924 4 i915,drm_kms_helper
lp 17759 0
dell_laptop 17369 0
dcdbas 14888 1 dell_laptop
dell_wmi 12681 0
joydev 17393 0
sparse_keymap 13948 1 dell_wmi
coretemp 13435 0
i2c_algo_bit 13413 1 i915
shpchp 37047 0
mei_me 18437 0
kvm_intel 143006 0
mei 78023 1 mei_me
lpc_ich 21093 0
parport 42313 3 lp,ppdev,parport_pc
serio_raw 13483 0
kvm 445551 1 kvm_intel
intel_ips 18484 0
soundcore 12680 1 snd
wmi 19193 1 dell_wmi
video 19058 1 i915
psmouse 106319 0
ahci 29929 5
atl1c 46050 0
libahci 32009 1 ahci
after observing lsmod you can see that there is no ext3 or jbd module. What am i missing here or why else there is no ext3 module. yet i have installed my operating system on a drive partitioned with ext3.
i have unloaded the ext3 module for inserting my own, by typing:
modprobe -r ext3
and then,
modeprobe ext3
But still the error persists. Please help me to solve the modprobe problem.
PS: I'm using Ubuntu.

Mac OS X: GNU parallel can't find the number of cores on a remote server

I used homebrew to install GNU parallel on my mac so I can run some tests remotely on my University's servers. I was quickly running through the tutorials, but when I ran
parallel -S <username>#$SERVER1 echo running on ::: <username>#$SERVER1
I got the message
parallel: Warning: Could not figure out number of cpus on <username#server> (). Using 1.
Possibly related, I never added parallel to my path and got the warning that "parallel" wasn't a recognized command, but parallel ran anyways and still echo'd correctly. This particular server has 16 cores, how can I get parallel to recognize them?
GNU Parallel is less tested on OS X as I do not have access to an OS X installation, so you have likely found a bug.
GNU Parallel has since 20120322 used these to find the number of CPUs:
sysctl -n hw.physicalcpu
sysctl -a hw 2>/dev/null | grep [^a-z]physicalcpu[^a-z] | awk '{ print \$2 }'
And the number of cores:
sysctl -n hw.logicalcpu
sysctl -a hw 2>/dev/null | grep [^a-z]logicalcpu[^a-z] | awk '{ print \$2 }'
Can you test what output you get from those?
Which version of GNU Parallel are you using?
As a work around you can force GNU Parallel to detect 16 cores:
parallel -S 16/<username>#$SERVER1 echo running on ::: <username>#$SERVER1
Since version 20140422 you have been able to export your path to the remote server:
parallel --env PATH -S 16/<username>#$SERVER1 echo running on ::: <username>#$SERVER1
That way you just need to add the dir where parallel lives on the server to your path on local machine. E.g. parallel on the remote server is in /home/u/user/bin/parallel:
PATH=$PATH:/home/u/user/bin parallel --env PATH -S <username>#$SERVER1 echo running on ::: <username>#$SERVER1
Information for Ole
My iMac (OSX MAvericks on Intel core i7) gives the following, which all looks correct:
sysctl -n hw.physicalcpu
4
sysctl -a hw
hw.ncpu: 8
hw.byteorder: 1234
hw.memsize: 17179869184
hw.activecpu: 8
hw.physicalcpu: 4
hw.physicalcpu_max: 4
hw.logicalcpu: 8
hw.logicalcpu_max: 8
hw.cputype: 7
hw.cpusubtype: 4
hw.cpu64bit_capable: 1
hw.cpufamily: 1418770316
hw.cacheconfig: 8 2 2 8 0 0 0 0 0 0
hw.cachesize: 17179869184 32768 262144 8388608 0 0 0 0 0 0
hw.pagesize: 4096
hw.busfrequency: 100000000
hw.busfrequency_min: 100000000
hw.busfrequency_max: 100000000
hw.cpufrequency: 3400000000
hw.cpufrequency_min: 3400000000
hw.cpufrequency_max: 3400000000
hw.cachelinesize: 64
hw.l1icachesize: 32768
hw.l1dcachesize: 32768
hw.l2cachesize: 262144
hw.l3cachesize: 8388608
hw.tbfrequency: 1000000000
hw.packages: 1
hw.optional.floatingpoint: 1
hw.optional.mmx: 1
hw.optional.sse: 1
hw.optional.sse2: 1
hw.optional.sse3: 1
hw.optional.supplementalsse3: 1
hw.optional.sse4_1: 1
hw.optional.sse4_2: 1
hw.optional.x86_64: 1
hw.optional.aes: 1
hw.optional.avx1_0: 1
hw.optional.rdrand: 0
hw.optional.f16c: 0
hw.optional.enfstrg: 0
hw.optional.fma: 0
hw.optional.avx2_0: 0
hw.optional.bmi1: 0
hw.optional.bmi2: 0
hw.optional.rtm: 0
hw.optional.hle: 0
hw.cputhreadtype: 1
hw.machine = x86_64
hw.model = iMac12,2
hw.ncpu = 8
hw.byteorder = 1234
hw.physmem = 2147483648
hw.usermem = 521064448
hw.pagesize = 4096
hw.epoch = 0
hw.vectorunit = 1
hw.busfrequency = 100000000
hw.cpufrequency = 3400000000
hw.cachelinesize = 64
hw.l1icachesize = 32768
hw.l1dcachesize = 32768
hw.l2settings = 1
hw.l2cachesize = 262144
hw.l3settings = 1
hw.l3cachesize = 8388608
hw.tbfrequency = 1000000000
hw.memsize = 17179869184
hw.availcpu = 8
sysctl -n hw.logicalcpu
8

get ec2 pricing programmatically?

Is there a way to get AWS pricing programmatically (cost per hour of each instance type, cost per GB/month of storage on S3, and etc)?
Also, are there cost monitoring tools? For example, is there a tool that can report your EC2 instance usage on an hourly basis (versus a monthly basis, which is what Amazon does)?
Thanks in advance.
UPDATE:
There is now AWS pricing API:
https://aws.amazon.com/blogs/aws/new-aws-price-list-api/
Orginal answer:
The price lists are available in form of JSONP files (you need to strip off function call) which are used by the AWS pricing pages. Each table (and each tab for table) has separate JSON file. It is not an API maybe, but definitely computer digestible. Here is a list that supports EC2 pricing page (as of 17 December 2014):
On-demand Linux: http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js
On-demand RedHat: http://a0.awsstatic.com/pricing/1/ec2/rhel-od.min.js
On-demand SUSE: http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js
On-demand Windows: http://a0.awsstatic.com/pricing/1/ec2/mswin-od.min.js
On-demand SQL Standard: http://a0.awsstatic.com/pricing/1/ec2/mswinSQL-od.min.js
On-demand SQL Web: http://a0.awsstatic.com/pricing/1/ec2/mswinSQLWeb-od.min.js
Reserved Linux: http://a0.awsstatic.com/pricing/1/ec2/ri-v2/linux-unix-shared.min.js
Reserved RedHat: http://a0.awsstatic.com/pricing/1/ec2/ri-v2/red-hat-enterprise-linux-shared.min.js
Reserved SUSE: http://a0.awsstatic.com/pricing/1/ec2/ri-v2/suse-linux-shared.min.js
Reserved Windows: http://a0.awsstatic.com/pricing/1/ec2/ri-v2/windows-shared.min.js
Reserved SQL Standard: http://a0.awsstatic.com/pricing/1/ec2/ri-v2/windows-with-sql-server-standard-shared.min.js
Reserved SQL Web: http://a0.awsstatic.com/pricing/1/ec2/ri-v2/windows-with-sql-server-web-shared.min.js
Reserved Spot instances: http://spot-price.s3.amazonaws.com/spot.js
Data transfer: http://a0.awsstatic.com/pricing/1/ec2/pricing-data-transfer-with-regions.min.js
EBS optimized: http://a0.awsstatic.com/pricing/1/ec2/pricing-ebs-optimized-instances.min.js
EBS: http://a0.awsstatic.com/pricing/1/ebs/pricing-ebs.min.js
Elastic IP: http://a0.awsstatic.com/pricing/1/ec2/pricing-elastic-ips.min.js
CloudWatch: http://a0.awsstatic.com/pricing/1/cloudwatch/pricing-cloudwatch.min.js
ELB: http://a0.awsstatic.com/pricing/1/ec2/pricing-elb.min.js
EMR: https://a0.awsstatic.com/pricing/1/emr/pricing-emr.min.js
WARNING: The endpoints change from time to time and often old URL is still there with old values. It is best to check what is the current status rather than relying on links provided in this thread.
So, here is a short command to get current set or URLs from any AWS pricing page. Example based on EC2. Run it on Linux or Cygwin. Actually this command was used to create the list above.
curl http://aws.amazon.com/ec2/pricing/ 2>/dev/null | grep 'model:' | sed -e "s/.*'\(.*\)'.*/http:\\1/"
For those who don't like command line, you can also check in a web browser network console (you get there with F12), filter with JS objects:
Just to let you know that they seem to have changed the JSON addresses. It includes the new C3 instance types
Update 01/21/2014: addresses changed again. Please note that these are JS files with a callback function that should be removed so that it becomes a parsable JSON.
Update 09/21/2014: addresses changed once again and include the new T2 instace types. To be treated as JSON files, the initial comments and the callback function should be removed and the keys should be wrapped in double quotes.
On Demand
Linux: http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js
Windows: http://a0.awsstatic.com/pricing/1/ec2/mswin-od.min.js
RHEL: http://a0.awsstatic.com/pricing/1/ec2/rhel-od.min.js
SLES: http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js
Windows w/ SQL Std: http://a0.awsstatic.com/pricing/1/ec2/mswinSQL-od.min.js
Windows w/ SQL Web: http://a0.awsstatic.com/pricing/1/ec2/mswinSQLWeb-od.min.js
Reserved Light
Linux: http://a0.awsstatic.com/pricing/1/ec2/linux-ri-light.min.js
Windows: http://a0.awsstatic.com/pricing/1/ec2/mswin-ri-light.min.js
RHEL: http://a0.awsstatic.com/pricing/1/ec2/rhel-ri-light.min.js
SLES: http://a0.awsstatic.com/pricing/1/ec2/sles-ri-light.min.js
Windows w/ SQL Std: http://a0.awsstatic.com/pricing/1/ec2/mswinSQL-ri-light.min.js
Windows w/ SQL Web: http://a0.awsstatic.com/pricing/1/ec2/mswinSQLWeb-ri-light.min.js
Reserved Medium
Linux: http://a0.awsstatic.com/pricing/1/ec2/linux-ri-medium.min.js
Windows: http://a0.awsstatic.com/pricing/1/ec2/mswin-ri-medium.min.js
RHEL: http://a0.awsstatic.com/pricing/1/ec2/rhel-ri-medium.min.js
SLES: http://a0.awsstatic.com/pricing/1/ec2/sles-ri-medium.min.js
Windows w/ SQL Std: http://a0.awsstatic.com/pricing/1/ec2/mswinSQL-ri-medium.min.js
Windows w/ SQL Web: http://a0.awsstatic.com/pricing/1/ec2/mswinSQLWeb-ri-medium.min.js
Reserved Heavy
Linux: http://a0.awsstatic.com/pricing/1/ec2/linux-ri-heavy.min.js
Windows: http://a0.awsstatic.com/pricing/1/ec2/mswin-ri-heavy.min.js
RHEL: http://a0.awsstatic.com/pricing/1/ec2/rhel-ri-heavy.min.js
SLES: http://a0.awsstatic.com/pricing/1/ec2/sles-ri-heavy.min.js
Windows w/ SQL Std: http://a0.awsstatic.com/pricing/1/ec2/mswinSQL-ri-heavy.min.js
Windows w/ SQL Web: http://a0.awsstatic.com/pricing/1/ec2/mswinSQLWeb-ri-heavy.min.js
Other
Spot Instances: http://spot-price.s3.amazonaws.com/spot.js
Data Transfer: http://a0.awsstatic.com/pricing/1/ec2/pricing-data-transfer-with-regions.min.js
EBS-Optimized Instances Surcharge: http://a0.awsstatic.com/pricing/1/ec2/pricing-ebs-optimized-instances.min.js
EBS: http://a0.awsstatic.com/pricing/1/ec2/pricing-ebs.min.js
Elastic IP: http://a0.awsstatic.com/pricing/1/ec2/pricing-elastic-ips.min.js
CloudWatch: http://a0.awsstatic.com/pricing/1/ec2/pricing-cloudwatch.min.js
ELB: http://a0.awsstatic.com/pricing/1/ec2/pricing-elb.min.js
Previous endpoint: http://aws-assets-pricing-prod.s3.amazonaws.com/pricing/ec2/linux-od.js
using the aws cli (in the examples below, I have also included how the same thing can be executed using jq)
to get a list of service codes:
aws pricing describe-services --region us-east-1
to get a list of service codes (with jq):
aws pricing describe-services --region us-east-1 | jq -r '.Services[] | .ServiceCode'
which will return values like:
AmazonEC2
AmazonS3
AmazonRoute53
[...]
to get a list of attributes for a given service code:
aws pricing describe-services --service-code AmazonEC2 --region us-east-1
to get a list of attributes for a given service code (with jq):
aws pricing describe-services --service-code AmazonEC2 --region us-east-1 | jq -r '.Services[] | .AttributeNames[]'
which will return values like:
instancesku
location
memory
vcpu
volumeType
[...]
to get pricing info now that you have a service code and attribute:
(this will take a while since it is every sku for the service code, so I will show examples using filtering further down)
aws pricing get-products --service-code AmazonEC2 --region us-east-1
to get pricing info now that you have a service code and attribute using a filter on instanceType and another for location:
aws pricing get-products --service-code AmazonEC2 --filters "Type=TERM_MATCH,Field=instanceType,Value=m5.xlarge" "Type=TERM_MATCH,Field=location,Value=US East (N. Virginia)" --region us-east-1
to get pricing info now that you have a service code and attribute using a filter on instanceType and another for location (with jq):
aws pricing get-products --service-code AmazonEC2 --filters "Type=TERM_MATCH,Field=instanceType,Value=m5.xlarge" "Type=TERM_MATCH,Field=location,Value=US East (N. Virginia)" --region us-east-1 | jq -rc '.PriceList[]' | jq -r '[ .product.attributes.servicecode, .product.attributes.location, .product.attributes.instancesku?, .product.attributes.instanceType, .product.attributes.usagetype, .product.attributes.operatingSystem, .product.attributes.memory, .product.attributes.physicalProcessor, .product.attributes.processorArchitecture, .product.attributes.vcpu, .product.attributes.currentGeneration, .terms.OnDemand[].priceDimensions[].unit, .terms.OnDemand[].priceDimensions[].pricePerUnit.USD, .terms.OnDemand[].priceDimensions[].description] | #csv'
which will return values like:
"AmazonEC2","US East (N. Virginia)","EWZRARGKPMTYQJFP","m5.xlarge","UnusedDed:m5.xlarge","Linux","16 GiB","Intel Xeon Platinum 8175 (Skylake)","64-bit","4","Yes","Hrs","0.6840000000","$0.684 per Dedicated Unused Reservation Linux with SQL Std m5.xlarge Instance Hour"```
[...]
In addition to #arturhoo's answer which provides the EC2 spots
You can obtain the historic prices with the CLI tool
aws ec2 describe-spot-price-history \
--instance-types m1.xlarge \
--product-description "Linux/UNIX (Amazon VPC)" \
--start-time 2016-10-31T03:00:00 \
--end-time 2016-10-31T03:16:00 \
--query 'SpotPriceHistory[*].[Timestamp,SpotPrice]'
which takes the spot price between 3:00am and 3:16am Monday 31st October 2016 (UTC)
[
[
"2016-10-31T03:06:12.000Z",
"0.041500"
],
[
"2016-10-31T03:00:26.000Z",
"0.041600"
],
[
"2016-10-31T02:59:14.000Z",
"0.041500"
],
[
"2016-10-31T02:00:18.000Z",
"0.040600"
],
[
"2016-10-30T23:55:06.000Z",
"0.043200"
]
]
This ruby gem wraps the JSON pricing data provided by Amazon and provides a simple interface, which takes care of mapping the region and instance type names to the ones used in the EC2 API.
https://github.com/sonian/amazon-pricing
Beside the official AWS JSON endpoint, https://ec2.shop is also an option. It respond both to json and text based(so you can use grep, awk etc).
curl -L 'ec2.shop?filter=.large'
Instance Type Memory vCPUs Storage Network Price Monthly Spot Price
m6g.large 8 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.0770 56.210 0.0357
t3.large 8 GiB 2 vCPUs EBS only Up to 5 Gigabit 0.0832 60.736 0.0250
m5a.large 8 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.0860 62.780 0.0345
i3en.large 16 GiB 2 vCPUs 1 x 1250 NVMe SSD Up to 25 Gigabit 0.2260 164.980 0.0678
r4.large 15.25 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.1330 97.090 0.0343
r5.large 16 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.1260 91.980 0.0356
r5a.large 16 GiB 2 vCPUs EBS only 10 Gigabit 0.1130 82.490 0.0356
r5dn.large 16 GiB 2 vCPUs 1 x 75 NVMe SSD Up to 25 Gigabit 0.1670 121.910 0.0356
t3a.large 8 GiB 2 vCPUs EBS only Up to 5 Gigabit 0.0752 54.896 0.0226
m4.large 8 GiB 2 vCPUs EBS only Moderate 0.1000 73.000 0.0362
i3.large 15.25 GiB 2 vCPUs 1 x 475 NVMe SSD Up to 10 Gigabit 0.1560 113.880 0.0468
m5dn.large 8 GiB 2 vCPUs 1 x 75 NVMe SSD Up to 25 Gigabit 0.1360 99.280 0.0340
m5d.large 8 GiB 2 vCPUs 1 x 75 NVMe SSD Up to 10 Gigabit 0.1130 82.490 0.0340
t2.large 8 GiB 2 vCPUs EBS only Low to Moderate 0.0928 67.744 0.0278
z1d.large 16 GiB 2 vCPUs 1 x 75 NVMe SSD Up to 10 Gigabit 0.1860 135.780 0.0558
c5.large 4 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.0850 62.050 0.0324
m5ad.large 8 GiB 2 vCPUs 1 x 75 NVMe SSD Up to 10 Gigabit 0.1030 75.190 0.0345
r6g.large 16 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.1008 73.584 0.0374
r5d.large 16 GiB 2 vCPUs 1 x 75 NVMe SSD 10 Gigabit 0.1440 105.120 0.0356
r5n.large 16 GiB 2 vCPUs EBS only Up to 25 Gigabit 0.1490 108.770 0.0356
r5ad.large 16 GiB 2 vCPUs 1 x 75 NVMe SSD 10 Gigabit 0.1310 95.630 0.0356
c6g.large 4 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.0680 49.640 0.0340
m5n.large 8 GiB 2 vCPUs EBS only Up to 25 Gigabit 0.1190 86.870 0.0340
c4.large 3.75 GiB 2 vCPUs EBS only Moderate 0.1000 73.000 0.0308
c5a.large 4 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.0770 56.210 0.0324
c5d.large 4 GiB 2 vCPUs 1 x 50 NVMe SSD Up to 10 Gigabit 0.0960 70.080 0.0324
m5.large 8 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.0960 70.080 0.0341
c5n.large 5.25 GiB 2 vCPUs EBS only Up to 25 Gigabit 0.1080 78.840 0.0326
a1.large 4 GiB 2 vCPUs EBS only Up to 10 Gigabit 0.0510 37.230 0.0227
c3.large 3.75 GiB 2 vCPUs 2 x 16 SSD Moderate 0.1050 76.650 0.0294
r3.large 15.25 GiB 2 vCPUs 1 x 32 SSD Moderate 0.1660 121.180 0.0323
m1.large 7.5 GiB 2 vCPUs 2 x 420 SSD Moderate 0.1750 127.750 0.0175
m3.large 7.5 GiB 2 vCPUs 1 x 32 SSD Moderate 0.1330 97.090 0.0308
Also JSON like this:
curl -sL 'ec2.shop?filter=m4' -H 'accept: json' | jq .
{
"Prices": [
{
"InstanceType": "m4.16xlarge",
"Memory": "256 GiB",
"VCPUS": 64,
"Storage": "EBS only",
"Network": "20 Gigabit",
"Cost": 3.2,
"MonthlyPrice": 2336,
"SpotPrice": "0.9479"
},
{
"InstanceType": "m4.large",
"Memory": "8 GiB",
"VCPUS": 2,
"Storage": "EBS only",
"Network": "Moderate",
"Cost": 0.1,
"MonthlyPrice": 73,
"SpotPrice": "0.0362"
},
{
"InstanceType": "m4.2xlarge",
"Memory": "32 GiB",
"VCPUS": 8,
"Storage": "EBS only",
"Network": "High",
"Cost": 0.4,
"MonthlyPrice": 292,
"SpotPrice": "0.1504"
},
{
"InstanceType": "m4.4xlarge",
"Memory": "64 GiB",
"VCPUS": 16,
"Storage": "EBS only",
"Network": "High",
"Cost": 0.8,
"MonthlyPrice": 584,
"SpotPrice": "0.3168"
},
{
"InstanceType": "m4.xlarge",
"Memory": "16 GiB",
"VCPUS": 4,
"Storage": "EBS only",
"Network": "High",
"Cost": 0.2,
"MonthlyPrice": 146,
"SpotPrice": "0.0661"
},
{
"InstanceType": "m4.10xlarge",
"Memory": "160 GiB",
"VCPUS": 40,
"Storage": "EBS only",
"Network": "10 Gigabit",
"Cost": 2,
"MonthlyPrice": 1460,
"SpotPrice": "0.7050"
}
]
}
If you are using golang, I wrote a library that can query the data using the
"https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/{offer_code}/current/index.{format}"
format.
https://github.com/Chronojam/aws-pricing-api
import (
"github.com/chronojam/aws-pricing-api/types/schema"
)
func main() {
ec2 := &schema.AmazonEC2{}
// Populate this object with new pricing data
err := ec2.Refresh()
if err != nil {
panic(err)
}
// Get the price of all c4.Large instances,
// running linux, on shared tenancy
c4Large := []*schema.AmazonEC2_Product{}
for _, p := range ec2.Products {
if p.Attributes.InstanceType == "c4.large" &&
p.Attributes.OperatingSystem == "Linux" &&
p.Attributes.Tenancy == "Shared" {
c4Large = append(c4Large, p)
}
}
}
AWS has launched the new price list API for programming integration.
URL Syntax:
https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/{offer_code}/current/index.{format}
To get list of supporting services:
https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/index.json
AWS blog Referance: https://aws.amazon.com/blogs/aws/new-aws-price-list-api/
I am the author of an open-source tool called ec2-cost-calculate that will "report your EC2 instance usage on an hourly basis" - the tool is available at awsmissingtools.com. Output can be hourly, daily, monthly. Two versions of the tool exist, one written in Ruby and another written in bash.
As Amazon has recently changed the pricing scheme for EC2 instances (no more Medium or Light, only Heavy which has multiple payment options - allUpfront, partialUpfront, noUpfront) and also some time ago separated the old generation instances from the current ones, the list of undocumented pricing API links has changed as well the structure of JSON provisioned by these links.
The full list if links of EC2 pricing undocumented API with descriptions, as well as the Python module for convenient access and structured output of pricing in JSON, CSV or Table formats can be found in the following repository:
https://github.com/ilia-semenov/awspricingfull
If you're using Go, I wrote a package to decode the data into a struct, based on the files linked to in #okrasz's answer
https://github.com/recursionpharma/ec2prices
Feel free to contribute with more pricing data.
here's a bash implementation, maintained as a gist that will give you pricing in a concise csv file for on-demand, license-free instances.
it works by parsing the nearly 3gb ec2 pricing file and filtering out all the reserved instance and private customer prices that are inexplicably included in the only free mechanism aws provides for obtaining programmatically parse-able pricing data and results in a price.csv file of just over 7000 lines.
#!/usr/bin/env bash
# csv filenames
raw_path=/tmp/ec2.csv
machine_path=/tmp/machine.csv
price_path=/tmp/price.csv
region_path=/tmp/region.csv
# dependencies
for package in coreutils curl datamash grep miller python3-csvkit; do
if ! dnf list installed ${package} &> /dev/null; then
sudo dnf install -y ${package}
fi
done
# fetch raw data from aws
if [ ! -s ${raw_path} ]; then
curl -Lo ${raw_path} https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.csv
fi
# build machine list
if [ ! -s ${machine_path} ]; then
echo '"id","current-generation","family","vcpu","processor","clock","memory","storage","network","architecture"' > ${machine_path}
tail -n +7 ${raw_path} | cut -d , -f 20-29 | grep -v '"AWS Region"' | grep -v '"NA","NA","NA"' | grep -v ',,,,,,,,,' | sort -u >> ${machine_path}
fi
# build price list, filtering out everything but license-free, on-demand instances in regions available to the public
if [ ! -s ${price_path} ]; then
echo machine,region,price > ${price_path}
cat ${raw_path} | grep '"Linux","No License required"' | grep -v 'SQL' | grep -v '"Reserved"' | grep -v '"0.0000000000"' | grep -v 'Unused Reservation' | grep -v 'Dedicated' | cut -d , -f 10,20,85 | egrep '"(af|ap|ca|eu|me|sa|us)-(north|south|east|west|central)(east|west)?-[1-3]"' | mlr --csv --implicit-csv-header reorder -f 2,3,1 | grep -v '2,3,1' | sort >> ${price_path}
fi
# build region list, filtering out private customer regions
if [ ! -s ${region_path} ]; then
echo '"id","name"' > ${region_path}
tail -n +7 ${raw_path} | cut -d , -f 18,85 | sort -u | datamash -t , reverse | egrep '"(af|ap|ca|eu|me|sa|us)-(north|south|east|west|central)(east|west)?-[1-3]"' | sort >> ${region_path}
fi

Resources