Select a set of values from Array based on value - powershell

I am using following PowerShlell to get the list of available physical disk.
$disks=((Get-PhysicalDisk -CanPool $true)|Select-Object PhysicalLocation)
The output of above code is as shown below
Integrated : Adapter 3 : Port 0 : Target 0 : LUN 7
Integrated : Adapter 3 : Port 0 : Target 0 : LUN 0
Integrated : Adapter 3 : Port 0 : Target 0 : LUN 5
Integrated : Adapter 3 : Port 0 : Target 0 : LUN 2
Integrated : Adapter 3 : Port 0 : Target 0 : LUN 6
Integrated : Adapter 3 : Port 0 : Target 0 : LUN 4
Integrated : Adapter 3 : Port 0 : Target 0 : LUN 1
Integrated : Adapter 3 : Port 0 : Target 0 : LUN 3
Integrated : Adapter 3 : Port 0 : Target 0 : LUN 8
However, form the collection I want to select a set of LUN e.g LUN from 5 to 8 to create a storage pool using
New-StoragePool
Thanks

You don't need to put the expressions in parenthesis. You can try something like below. This regex will help you to get the desired result.
Get-PhysicalDisk -CanPool $true | Foreach-Object -Process {
$_.PhysicalLocation | Select-String -Pattern 'LUN.[5-8]'
}

Related

Robocopy behaves differently when running directly or from powershell script

I have a script that copies a file from a network location to a local folder using robocopy.
When I run following powershell 7 script from Visual Code, or execute the command directly in PS, only 1 file is copied as intended. If a run the script in powershell 4 files are copied. How can I copy the single file running from the script.
$dbname = "domoticz.db"
$sourcedir="\\ix2\PiBackup\domoticz\"
$targetdir="C:\tmp\DomoticzScripts\"
$dbfile = $targetdir + $dbname
robocopy $sourcedir $targetdir $db -njh
Output running it directly or VS Code debugger
New Dir 1 \\ix2\PiBackup\domoticz\
100% New File 8.9 m domoticz.db
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 1 0 0 0 0
Files : 1 1 0 0 0 0
Bytes : 8.96 m 8.96 m 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 70709894 Bytes/sec.
Speed : 4046.052 MegaBytes/min.
Ended : zaterdag 30 mei 2020 11:45:40
Running it in a script
New Dir 4 \\ix2\PiBackup\domoticz\
100% New File 8.9 m domoticz.db
100% New File 32768 domoticz.db-shm
100% New File 0 domoticz.db-wal
100% New File 9.0 m domoticz_.db
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 1 0 0 0 0
Files : 4 4 0 0 0 0
Bytes : 18.05 m 18.05 m 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 75125841 Bytes/sec.
Speed : 4298.735 MegaBytes/min.
Ended : zaterdag 30 mei 2020 11:47:06

Can`t connect to VPN using nm-l2tp-service

I using Centos 7 machine and want to connect to l2tp VPN using nm-l2tp-service:
Output of service:
[gefalko#localhost ~]$ sudo /usr/libexec/nm-l2tp-service --debug
nm-l2tp[20335] nm-l2tp-service (version 1.2.10-1.el7) starting...
nm-l2tp[20335] uses default --bus-name "org.freedesktop.NetworkManager.l2tp"
nm-l2tp[20335] ipsec enable flag: yes
** Message: Check port 1701
connection
id : "L2TP IPSec (PSK) - otravo" (s)
uuid : "49a95a8c-275b-464b-8f62-a7639b48e966" (s)
interface-name : NULL (sd)
type : "vpn" (s)
permissions : ["user:gefalko:"] (s)
autoconnect : FALSE (s)
autoconnect-priority : 0 (sd)
autoconnect-retries : -1 (sd)
timestamp : 0 (sd)
read-only : FALSE (sd)
zone : NULL (sd)
master : NULL (sd)
slave-type : NULL (sd)
autoconnect-slaves : ((NMSettingConnectionAutoconnectSlaves) NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES_DEFAULT) (sd)
secondaries : NULL (sd)
gateway-ping-timeout : 0 (sd)
metered : ((NMMetered) NM_METERED_UNKNOWN) (sd)
lldp : -1 (sd)
stable-id : NULL (sd)
auth-retries : -1 (sd)
ipv6
method : "auto" (s)
dns : [] (s)
dns-search : [] (s)
dns-options : NULL (sd)
dns-priority : 0 (sd)
addresses : ((GPtrArray*) 0x1e8f780) (s)
gateway : NULL (sd)
routes : ((GPtrArray*) 0x1e8f6e0) (s)
route-metric : -1 (sd)
route-table : 0 (sd)
ignore-auto-routes : FALSE (sd)
ignore-auto-dns : FALSE (sd)
dhcp-hostname : NULL (sd)
dhcp-send-hostname : TRUE (sd)
never-default : FALSE (sd)
may-fail : TRUE (sd)
dad-timeout : -1 (sd)
dhcp-timeout : 0 (sd)
ip6-privacy : ((NMSettingIP6ConfigPrivacy) NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN) (sd)
addr-gen-mode : 1 (sd)
token : NULL (sd)
proxy
method : 0 (sd)
browser-only : FALSE (sd)
pac-url : NULL (sd)
pac-script : NULL (sd)
vpn
service-type : "org.freedesktop.NetworkManager.l2tp" (s)
user-name : "gefalko" (s)
persistent : FALSE (sd)
data : ((GHashTable*) 0x1e764c0) (s)
secrets : ((GHashTable*) 0x1e76400) (s)
timeout : 0 (sd)
ipv4
method : "auto" (s)
dns : [] (s)
dns-search : [] (s)
dns-options : NULL (sd)
dns-priority : 0 (sd)
addresses : ((GPtrArray*) 0x1e8f560) (s)
gateway : NULL (sd)
routes : ((GPtrArray*) 0x1e8f600) (s)
route-metric : -1 (sd)
route-table : 0 (sd)
ignore-auto-routes : FALSE (sd)
ignore-auto-dns : FALSE (sd)
dhcp-hostname : NULL (sd)
dhcp-send-hostname : TRUE (sd)
never-default : FALSE (sd)
may-fail : TRUE (sd)
dad-timeout : -1 (sd)
dhcp-timeout : 0 (sd)
dhcp-client-id : NULL (sd)
dhcp-fqdn : NULL (sd)
nm-l2tp[20335] starting ipsec
Redirecting to: systemctl stop ipsec.service
warning: could not open include filename: '/etc/ipsec.d/.conf'
warning: could not open include filename: '/etc/ipsec.d/.conf'
warning: could not open include filename: '/etc/ipsec.d/.conf'
warning: could not open include filename: '/etc/ipsec.d/.conf'
Redirecting to: systemctl start ipsec.service
002 listening for IKE messages
002 adding interface virbr0/virbr0 192.168.122.1:500
002 adding interface virbr0/virbr0 192.168.122.1:4500
002 adding interface wlp2s0/wlp2s0 192.168.1.176:500
002 adding interface wlp2s0/wlp2s0 192.168.1.176:4500
002 adding interface lo/lo 127.0.0.1:500
002 adding interface lo/lo 127.0.0.1:4500
002 adding interface lo/lo ::1:500
002 loading secrets from "/etc/ipsec.secrets"
002 loading secrets from "/etc/ipsec.d/nm-l2tp-ipsec-49a95a8c-275b-464b-8f62-a7639b48e966.secrets"
opening file: /var/run/nm-l2tp-ipsec-49a95a8c-275b-464b-8f62-a7639b48e966.conf
debugging mode enabled
end of file /var/run/nm-l2tp-ipsec-49a95a8c-275b-464b-8f62-a7639b48e966.conf
Loading conn 49a95a8c-275b-464b-8f62-a7639b48e966
starter: left is KH_DEFAULTROUTE
loading named conns: 49a95a8c-275b-464b-8f62-a7639b48e966
seeking_src = 1, seeking_gateway = 1, has_peer = 1
seeking_src = 0, seeking_gateway = 1, has_dst = 1
dst via 192.168.1.254 dev wlp2s0 src table 254
set nexthop: 192.168.1.254
dst 192.168.1.0 via dev wlp2s0 src 192.168.1.176 table 254
dst 192.168.122.0 via dev virbr0 src 192.168.122.1 table 254
dst 127.0.0.0 via dev lo src 127.0.0.1 table 255 (ignored)
dst 127.0.0.0 via dev lo src 127.0.0.1 table 255 (ignored)
dst 127.0.0.1 via dev lo src 127.0.0.1 table 255 (ignored)
dst 127.255.255.255 via dev lo src 127.0.0.1 table 255 (ignored)
dst 192.168.1.0 via dev wlp2s0 src 192.168.1.176 table 255 (ignored)
dst 192.168.1.176 via dev wlp2s0 src 192.168.1.176 table 255 (ignored)
dst 192.168.1.255 via dev wlp2s0 src 192.168.1.176 table 255 (ignored)
dst 192.168.122.0 via dev virbr0 src 192.168.122.1 table 255 (ignored)
dst 192.168.122.1 via dev virbr0 src 192.168.122.1 table 255 (ignored)
dst 192.168.122.255 via dev virbr0 src 192.168.122.1 table 255 (ignored)
seeking_src = 1, seeking_gateway = 0, has_peer = 1
seeking_src = 1, seeking_gateway = 0, has_dst = 1
dst 192.168.1.254 via dev wlp2s0 src 192.168.1.176 table 254
set addr: 192.168.1.176
seeking_src = 0, seeking_gateway = 0, has_peer = 1
conn: "49a95a8c-275b-464b-8f62-a7639b48e966" labeled_ipsec=0
conn: "49a95a8c-275b-464b-8f62-a7639b48e966" modecfgdns=(null)
conn: "49a95a8c-275b-464b-8f62-a7639b48e966" modecfgdomains=(null)
conn: "49a95a8c-275b-464b-8f62-a7639b48e966" modecfgbanner=(null)
conn: "49a95a8c-275b-464b-8f62-a7639b48e966" mark=(null)
conn: "49a95a8c-275b-464b-8f62-a7639b48e966" mark-in=(null)
conn: "49a95a8c-275b-464b-8f62-a7639b48e966" mark-out=(null)
conn: "49a95a8c-275b-464b-8f62-a7639b48e966" vti_iface=(null)
002 added connection description "49a95a8c-275b-464b-8f62-a7639b48e966"
nm-l2tp[20335] Spawned ipsec auto --up script with PID 21334.
002 "49a95a8c-275b-464b-8f62-a7639b48e966" #1: initiating Main Mode
104 "49a95a8c-275b-464b-8f62-a7639b48e966" #1: STATE_MAIN_I1: initiate
010 "49a95a8c-275b-464b-8f62-a7639b48e966" #1: STATE_MAIN_I1: retransmission; will wait 0.5 seconds for response
010 "49a95a8c-275b-464b-8f62-a7639b48e966" #1: STATE_MAIN_I1: retransmission; will wait 1 seconds for response
010 "49a95a8c-275b-464b-8f62-a7639b48e966" #1: STATE_MAIN_I1: retransmission; will wait 2 seconds for response
010 "49a95a8c-275b-464b-8f62-a7639b48e966" #1: STATE_MAIN_I1: retransmission; will wait 4 seconds for response
010 "49a95a8c-275b-464b-8f62-a7639b48e966" #1: STATE_MAIN_I1: retransmission; will wait 8 seconds for response
nm-l2tp[20335] Timeout trying to establish IPsec connection
nm-l2tp[20335] Terminating ipsec script with PID 21334.
nm-l2tp[20335] Could not establish IPsec tunnel.
(nm-l2tp-service:20335): GLib-GIO-CRITICAL **: g_dbus_method_invocation_take_error: assertion 'error != NULL' failed
010 "49a95a8c-275b-464b-8f62-a7639b48e966" #1: STATE_MAIN_I1: retransmission; will wait 16 seconds for response
I believe you need to set the IPsec phase 1 and 2 algorithms to the same as what the VPN server is using, or reconfigure the VPN server to offer stronger proposals.

compare-object issue using powershell

looking for the best way to compare two system.objects. tried the compare-object option, doesn't seem to give the desired output..
> $abc
BGP summary information for VRF default
Router identifier 192.168.0.3, local AS number 7251
Neighbor Status Codes: m - Under maintenance
Neighbor V AS MsgRcvd MsgSent InQ OutQ Up/Down State PfxRcd PfxAcc
10.12.103.119 4 7251 0 0 0 0 5d23h Connect
10.46.252.121 4 7251 0 0 0 0 5d23h Connect
> $def
BGP summary information for VRF default
Router identifier 192.168.0.3, local AS number 7251
Neighbor Status Codes: m - Under maintenance
Neighbor V AS MsgRcvd MsgSent InQ OutQ Up/Down State PfxRcd PfxAcc
10.12.103.119 4 7251 0 0 0 0 5d23h Active
10.46.252.121 4 7251 0 0 0 0 5d23h Estab
> $abc.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
> $def.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
> Compare-Object -ReferenceObject $abc -DifferenceObject $def
InputObject
-----------
BGP summary information for VRF default...
BGP summary information for VRF default...
You're dealing with strings ([System.String]), not [System.Objects] - the latter is only the base type, i.e., what [System.String] derives from.
The best way to compare 2 multiline strings is to compare them line by line, and to that end you must split them into an array of lines:
PS> Compare-Object ($abc -split '\r?\n') ($def -split '\r?\n')
InputObject SideIndicator
----------- -------------
10.12.103.119 4 7251 0 0 0 0 5d23h Active =>
10.46.252.121 4 7251 0 0 0 0 5d23h Estab =>
10.12.103.119 4 7251 0 0 0 0 5d23h Connect <=
10.46.252.121 4 7251 0 0 0 0 5d23h Connect <=
The => lines (the .SideIndicator property value of the output objects representing differences) indicate lines exclusive to the RHS ($def) whereas <= indicates lines exclusive to the LHS ($abc)

charToDate(x) error when using "seqformat" in TraMineR

I'm using TraMineR to inspect work trajectories.
When using the seqformat function (from SPELL data) with process = TRUE, and an external data frame for pdata, as follows :
situations <- seqformat(data[,1:4], id = 1, from = "SPELL", to = "STS",
begin = 3, end = 4, status = 2, right = NA,
process = TRUE, limit = 7644, pdata = pdata,
pvar = c("id","birth"))
I get an error message :
Error in charToDate(x) :
character string is not in a standard unambiguous format
I read many threads about that issue, but could not find any helpful solution.
Here are the structures of my data frames data and pdata :
str(data)
'data.frame': 2428 obs. of 9 variables:
$ ID_SQ : Factor w/ 798 levels "1","2","3","5",..: 1 1 1 1 1 2 2
...
$ SITUATION : chr "En poste" "En poste" "En poste" "En poste" ...
$ DATE_DE : Date, format: "1997-09-01" "1999-05-03" "2003-01-01"
...
$ DATE_A : Date, format: "1999-04-26" "2002-12-31" "2006-04-28"
...
$ SEXE : Factor w/ 2 levels "FĂ©minin","Masculin": 1 1 1 1 1 1 1
...
$ PROMO : Factor w/ 6 levels "1997","1998",..: 1 1 1 1 1 2 2 ...
$ DEPARTEMENT : Factor w/ 10 levels "BC","GCU","GE",..: 1 1 1 1 1 4 4 4
4 4 ...
$ NIVEAU_ADMISSION: Factor w/ 2 levels "En Premier Cycle",..: NA NA NA NA
NA 1 1 1 1 1 ...
$ FILIERE_SECTION : Factor w/ 4 levels "Cursus Classique",..: NA NA NA NA
NA 4 4 4 4 4 ...
str(pdata)
'data.frame': 798 obs. of 2 variables:
$ id : Factor w/ 798 levels "1","2","3","5",..: 1 2 3 4 5 6 7 8 9 10 ...
$ birth: Date, format: "1997-01-01" "1998-01-01" "1998-01-01" "2000-01-01" ...
It seems to me that all date formats are OK.
But, clearly, something's wrong.
What am I doing wrong?
Thank you in advance for your help,
Best,
Arnaud.
The seqformat function expects integer values for the begin and end dates of the spells. Actually, these integers should be the (time-)position in the state sequence and will correspond in your example to column numbers in the resulting STS format.
So you need to transform your dates into integer values.
=============
The error
Error in charToDate(x) : character string is not in a standard unambiguous format
occurs while the function tests whether pdata is the string "auto" with if(pdata == "auto"). This is because, when pdata contains dates, the test attempts to coerce "auto" into a date for the sake of comparison. The workaround is to input the dates as integers.

MongoDB indexing

We have a MongoDB collection containing nearly 40 million records. The current size of the collection is 5GB. The data stored in this collection contains following fields:
_id: "MongoDB id"
userid: "user id" (int)
mobile: "users mobile number" (int)
transaction: "transaction id" (int)
sms: "message sent to user mobile" (text)
created_dt: "unix timestamp of the transaction"
Apart from the index on _id (created by default), we have defined separate indexes on the mobile and transaction fields.
However, the following query takes anywhere between 60 to 120 seconds to complete:
{
mobile:<users mobile number>
}
I access MongoDB using RockMongo. MongoDB is hosted on a server with 16GB RAM. Nearly 8GB RAM on this server is free.
What is it that I am doing wrong here?
Update:
Output of explain:
{
"cursor" : "BasicCursor",
"nscanned" : 37145516,
"nscannedObjects" : 37145516,
"n" : 37145516,
"millis" : 296040,
"nYields" : 1343,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
Output of mongostat at the time of the query
insert query update delete getmore command flushes mapped vsize res faults locked % idx miss % qr|qw ar|aw netIn netOut conn time
13 2 0 0 0 1 0 168g 336g 6.86g 1 1 0 0|0 1|0 21k 1k 19 11:30:04
16 0 0 0 0 1 0 168g 336g 6.88g 0 0.1 0 0|0 1|0 21k 1k 19 11:30:05
14 0 0 0 0 1 0 168g 336g 6.86g 0 0 0 0|0 1|0 29k 1k 19 11:30:06
10 0 0 0 0 1 0 168g 336g 6.86g 0 0 0 0|0 1|0 19k 1k 19 11:30:07
16 0 0 0 0 1 0 168g 336g 6.88g 0 0.1 0 0|0 1|0 21k 1k 19 11:30:08
9 0 0 0 0 1 0 168g 336g 6.89g 0 0 0 0|0 1|0 13k 1k 19 11:30:09
19 0 0 0 0 1 0 168g 336g 6.89g 0 0 0 0|0 1|0 27k 1k 19 11:30:10
12 0 0 0 0 1 0 168g 336g 6.89g 1 1.2 0 0|0 1|0 24k 1k 19 11:30:11
17 0 0 0 0 1 0 168g 336g 6.89g 1 1.7 0 0|0 1|0 31k 1k 19 11:30:12
15 0 0 0 0 1 0 168g 336g 6.89g 0 0 0 0|0 1|0 19k 1k 19 11:30:13
Update 2:
Until recently, we used to store another collection with about 1.3 billion documents in the same MongoDB server. This collection has now been removed (dropped). This may explain the mapped / vsize column in above output from mongostat.
The server also stores 6 other collections which have frequent inserts. The total storage size currently is about 35GB.
Update 3:
Indexes defined on the collection. Created using RockMongo.
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "mymongodb.transaction_sms_details",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"_transaction_mobile_" : 1
},
"ns" : "mymongodb.transaction_sms_details",
"background" : 1,
"name" : "mobile"
},
{
"v" : 1,
"key" : {
"_transaction_transaction_" : 1
},
"ns" : "mymongodb.transaction_sms_details",
"background" : 1,
"name" : "transaction"
}
]
The keys generated by RockMongo is apparently incorrect.
"_transaction_mobile_" : 1
"_transaction_transtion_" : 1
I don't know what's wrong with RockMongo, but I think this can fix the issue:
db.xxx.dropIndexes();
db.xxx.ensureIndex({mobile: 1});
db.xxx.ensureIndex({transaction: 1});
Notice: This may take VERY LONG time. Don't do this on a running production machine.