How to invoke ConvertFrom-String in PowerShell on Linux? - linux

Looking to use ConvertFrom-String on Linux as per the example from the help file:
**********************
PowerShell transcript start
Start time: 20230204142830
Username: mordor\nicholas
RunAs User: mordor\nicholas
Configuration Name:
Machine: mordor (Unix 5.15.0.58)
Host Application: /snap/powershell/229/opt/powershell/pwsh.dll
Process ID: 1193147
PSVersion: 7.3.2
PSEdition: Core
GitCommitId: 7.3.2
OS: Linux 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023
Platform: Unix
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.10032.0, 6.0.0, 6.1.0, 6.2.0, 7.0.0, 7.1.0, 7.2.0, 7.3.2
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
WSManStackVersion: 3.0
**********************
Transcript started, output file is /home/nicholas/powershell/PowerShell_transcript.mordor.ciSjO_A6.20230204142830.txt
PS /home/nicholas/powershell> $template = #'
{Name*:Phoebe Cat}, {phone:425-123-6789}, {age:6}
{Name*:Lucky Shot}, {phone:(206) 987-4321}, {age:12}
'#
PS /home/nicholas/powershell> $testText = #'
Phoebe Cat, 425-123-6789, 6
Lucky Shot, (206) 987-4321, 12
Elephant Wise, 425-888-7766, 87
Wild Shrimp, (111) 222-3333, 1
'#
PS /home/nicholas/powershell> $PersonalData = $testText | ConvertFrom-String -TemplateContent $template
ConvertFrom-String: The term 'ConvertFrom-String' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
ConvertFrom-String: The term 'ConvertFrom-String' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS /home/nicholas/powershell> $PersonalData = $testText | ConvertFrom-StringData -TemplateContent $template
PS /home/nicholas/powershell> TerminatingError(ConvertFrom-StringData): "A parameter cannot be found that matches parameter name 'TemplateContent'."
ConvertFrom-StringData: A parameter cannot be found that matches parameter name 'TemplateContent'.
ConvertFrom-StringData: A parameter cannot be found that matches parameter name 'TemplateContent'.
PS /home/nicholas/powershell> help ConvertFrom-String
PS /home/nicholas/powershell> help ConvertFrom-StringData
PS /home/nicholas/powershell> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.2
PSEdition Core
GitCommitId 7.3.2
OS Linux 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS /home/nicholas/powershell> lsb_release -a
No LSB modules are available.
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04 LTS
Release: 22.04
Codename: jammy
what throws me off here is that the help file loads fine, which would indicate that the component is installed. Perhaps that's an incorrect understanding.

ConvertFrom-String is available only in Windows PowerShell, the legacy, Windows-only edition of PowerShell - it was never ported to PowerShell (Core), the modern, cross-platform edition.
On Windows only, the cmdlet is technically still available, via the Windows PowerShell compatibility feature (which comes with its own limitations); however, for the reasons stated below, it's best to avoid this cmdlet altogether.
Note: ConvertFrom-String is not to be confused with the ConvertFrom-StringData cmdlet, which is available in PowerShell (Core) as well, on all supported platforms.
However, even in Windows PowerShell / on Windows there are good reasons to avoid use of this cmdlet:
It provides separator-based parsing as well as heuristics-based parsing based on templates containing example values.
The separator-based parsing applies automatic type conversions you cannot control, and the poorly documented template language results in behavior that is inherently hard to predict.

Related

How i could find my Linux distribution on amazon Linux AMI?

Amazon Web Services (AWS) offers an officially supported Amazon Machine Image AMI, but it doesn't indicate which Linux distribution it's based upon.
And we need the version of Linux distribution when installation software like : vagrant and so one ....
I use : **hostnamectl** command with result shown in the below :
Static hostname: a-1fxzvx1ww7twk
Pretty hostname: A-1FXZVX1WW7TWK
Icon name: computer-vm
Chassis: vm
Machine ID: 10c579b792b74c5bbababbcbd78df49e
Boot ID: e444cb9e35354d53a45c28fe7384bc7f
Virtualization: kvm
***Operating System: Amazon Linux 2***
CPE OS Name: cpe:2.3:o:amazon:amazon_linux:2
Kernel: Linux 4.14.181-142.260.amzn2.x86_64
Architecture: x86-64
As we see there isn't any information about the version of Linux distribution.
Also i use this command : pm –qa centos-release with the result of shown in the below :
Usage: rpm [-aKfgpqVcdLilsiv?] [-a|--all] [-f|--file] [-g|--group]
[-p|--package] [--pkgid] [--hdrid] [--triggeredby] [--whatrequires]
[--whatprovides] [--nomanifest] [-c|--configfiles] [-d|--docfiles]
[-L|--licensefiles] [--dump] [-l|--list] [--queryformat=QUERYFORMAT]
[-s|--state] [--nofiledigest] [--nofiles] [--nodeps] [--noscript]
[--allfiles] [--allmatches] [--badreloc] [-e|--erase <package>+]
[--excludedocs] [--excludepath=<path>] [--force]
[-F|--freshen <packagefile>+] [-h|--hash] [--ignorearch] [--ignoreos]
[--ignoresize] [-i|--install] [--justdb] [--nodeps] [--nofiledigest]
[--nocontexts] [--nocaps] [--noorder] [--noscripts] [--notriggers]
[--nocollections] [--oldpackage] [--percent] [--prefix=<dir>]
[--relocate=<old>=<new>] [--replacefiles] [--replacepkgs] [--test]
[-U|--upgrade <packagefile>+] [--reinstall=<packagefile>+]
[-D|--define 'MACRO EXPR'] [--undefine=MACRO] [-E|--eval 'EXPR']
[--macros=<FILE:...>] [--noplugins] [--nodigest] [--nosignature]
[--rcfile=<FILE:...>] [-r|--root ROOT] [--dbpath=DIRECTORY]
[--querytags] [--showrc] [--quiet] [-v|--verbose] [--version]
[-?|--help] [--usage] [--scripts] [--setperms] [--setugids]
[--setcaps] [--restore] [--conflicts] [--obsoletes] [--provides]
[--requires] [--info] [--changelog] [--xml] [--triggers] [--last]
[--dupes] [--filesbypkg] [--fileclass] [--filecolor] [--fscontext]
[--fileprovide] [--filerequire] [--filecaps]
But, still i couldn't see any information about the version of Linux distribution.
I write it in the answer below.
Do you know any other commands for this propose ?
Finally, i can find the magic command **cat /proc/version**
The result is:
Linux version 4.14.181-142.260.amzn2.x86_64 (mockbuild#ip-10-0-1-132) (gcc version 7.3.1 20180712 (**Red Hat 7.3.1-8**) (GCC)) #1 SMP Wed Jun 24 19:07:39 UTC 2020

Unable to Connect Sqoop to Oracle TimesTen through JDBC on Linux

I have installed Timesten database (full version) on linux (Linux is guest OS installed through Oracle viritual box with cloudera VM)
I am trying to run following sqoop command on linux and getting below errors
command
sqoop list-tables --connect jdbc:timesten:direct:dsn=sampledb_1122 --driver com.timesten.jdbc.TimesTenDriver
**error**
ERROR manager.SqlManager: Error reading database metadata: java.sql.SQLException: Problems with loading native library/missing methods: no ttJdbc in java.library.path
java.sql.SQLException: Problems with loading native library/missing methods: no ttJdbc in java.library.path
at com.timesten.jdbc.JdbcOdbcConnection.connect(JdbcOdbcConnection.java:1809)
at com.timesten.jdbc.TimesTenDriver.connect(TimesTenDriver.java:305)
at com.timesten.jdbc.TimesTenDriver.connect(TimesTenDriver.java:161)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:233)
at org.apache.sqoop.manager.SqlManager.makeConnection(SqlManager.java:878)
at org.apache.sqoop.manager.GenericJdbcManager.getConnection(GenericJdbcManager.java:52)
at org.apache.sqoop.manager.SqlManager.listTables(SqlManager.java:520)
at org.apache.sqoop.tool.ListTablesTool.run(ListTablesTool.java:49)
at org.apache.sqoop.Sqoop.run(Sqoop.java:143)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:179)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:218)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:227)
at org.apache.sqoop.Sqoop.main(Sqoop.java:236)
Could not retrieve tables list from server
18/02/18 18:56:04 ERROR tool.ListTablesTool: manager.listTables() returned null
TimesTen bin and lib folder location
/home/cloudra/timesten/TimesTen/tt1122_64/bin
/home/cloudera/timesten/TimesTen/tt1122_64/lib
Following values are setup in my environment and other parameters
USERNAME=cloudera
DESKTOP_SESSION=gnome
MAIL=/var/spool/mail/cloudera
PATH=/var/lib/sqoop:/home/cloudera/timesten/TimesTen/tt1122_64/bin:/home/cloudera/timesten/TimesTen/tt1122_64/lib:/home/cloudera/anaconda3/bin:/var/lib/sqoop:/home/cloudra/timesten/TimesTen/tt1122_64/bin:/home/cloudera/timesten/TimesTen/tt1122_64/lib:/home/cloudera/anaconda3/bin:/home/cloudera/anaconda3/bin:/usr/local/firefox:/sbin:/usr/java/jdk1.7.0_67-cloudera/bin:/usr/local/apache-ant/apache-ant-1.9.2/bin:/usr/local/apache-maven/apache-maven-3.0.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/cloudera/bin
PWD=/home/cloudera
THREAD_FLAGS=native
HOME=/home/cloudera
SHLVL=2
M2_HOME=/usr/local/apache-maven/apache-maven-3.0.4
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=cloudera
CVS_RSH=ssh
CLASSPATH=/home/cloudera/timesten/TimesTen/tt1122_64/lib/ttjdbc6.jar
[cloudera#quickstart ~]$ echo $LD_LIBRARY_PATH
/home/cloudera/timesten/TimesTen/tt1122_64/lib:/home/cloudera/timesten/TimesTen/tt1122_64/lib:
[cloudera#quickstart ~]$ java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
[cloudera#quickstart ~]$
cloudera#quickstart bin]$ ./ttversion
TimesTen Release 11.2.2.8.0 (64 bit Linux/x86_64) (tt1122_64:53396) 2015-01-20T08:36:31Z
Instance admin: cloudera
Instance home directory: /home/cloudera/timesten/TimesTen/tt1122_64
World accessible
Daemon home directory: /home/cloudera/timesten/TimesTen/tt1122_64/info
PL/SQL enabled.
In addition to above.. the ttjdbc6.jar file is located at following location
[cloudera#quickstart sqoop]$ pwd
/var/lib/sqoop
[cloudera#quickstart sqoop]$ ls -ltr
total 0
lrwxrwxrwx 1 root root 40 Jun 9 2015 mysql-connector-java.jar -> /usr/share/java/mysql-connector-java.jar
lrwxrwxrwx 1 root root 58 Feb 16 21:37 ttjdbc6.jar -> /home/cloudera/timesten/TimesTen/tt1122_64/lib/ttjdbc6.jar
[cloudera#quickstart timesten]$ pwd
/usr/lib/timesten
[cloudera#quickstart timesten]$ ls -ltr
total 276
-rwxrwxrwx 1 root root 279580 Feb 18 11:33 ttjdbc6.jar
Java_library_path output
[cloudera#quickstart timesten]$ java -XshowSettings:properties
Property settings:
awt.toolkit = sun.awt.X11.XToolkit
file.encoding = UTF-8
file.encoding.pkg = sun.io
file.separator = /
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
java.awt.printerjob = sun.print.PSPrinterJob
java.class.path = /home/cloudera/timesten/TimesTen/tt1122_64/lib/ttjdbc6.jar
java.class.version = 51.0
java.endorsed.dirs = /usr/java/jdk1.7.0_67-cloudera/jre/lib/endorsed
java.ext.dirs = /usr/java/jdk1.7.0_67-cloudera/jre/lib/ext
/usr/java/packages/lib/ext
java.home = /usr/java/jdk1.7.0_67-cloudera/jre
java.io.tmpdir = /tmp
java.library.path = /home/cloudera/timesten/TimesTen/tt1122_64/lib
/home/cloudera/timesten/TimesTen/tt1122_64/lib
/usr/java/packages/lib/amd64
/usr/lib64
/lib64
/lib
/usr/lib
java.runtime.name = Java(TM) SE Runtime Environment
java.runtime.version = 1.7.0_67-b01
I execute ttenv.sh scripts but it is not setting up any parameter when I check env parameters, so I had to do it manually.
Gurus and experts.. please help me here.. not sure what is the issue and why I am getting the above error.
Thanks for your help..
The key line here is this:
java.sql.SQLException: Problems with loading native library/missing methods:
no ttJdbc in java.library.path
The TimesTen JDBC driver is a type 1 / 2 driver and it relies on the underlying TimesTen native libraries. Specifically it needs several shared libraries located in <TimesTen_install_dir>/lib such as libttJdbc.so (the one that the error is complaining about), libtten.so etc. Typically you need to make sure that the java.library.path includes this directory (which it appears is the case) and that the CLASSPATH includes the ttjdbc7.jar file in that directory. Another possibility is that your TimesTen installation is a 'client only' installation in which case you cannot use the 'direct' driver and if you try to do so then you would get this exact error. I suggest checking to see if you actually have the files libttJdbc.so and libtten.so in <TimesTen_install_dir>/lib and if not, then this means you have a client only install and need to configure / use client/server connectivity instead.

How can I prevent vncserver from crashing when I start it?

I have an Ubuntu 16.04 droplet on DigitalOcean and I'm trying to set up remote desktop capabilities for it. I followed these instructions through Step 2. However, when I start the VNC server using the vncserver command, it goes haywire and bogs down the server until it crashes. Here are excerpts from the log file:
19/12/17 23:47:52 Xvnc version TightVNC-1.3.10
19/12/17 23:47:52 Copyright (C) 2000-2009 TightVNC Group
19/12/17 23:47:52 Copyright (C) 1999 AT&T Laboratories Cambridge
19/12/17 23:47:52 All Rights Reserved.
19/12/17 23:47:52 See http://www.tightvnc.com/ for information on TightVNC
19/12/17 23:47:52 Desktop name 'X' (thoughtful:1)
19/12/17 23:47:52 Protocol versions supported: 3.3, 3.7, 3.8, 3.7t, 3.8t
19/12/17 23:47:52 Listening for VNC connections on TCP port 5901
Font directory '/usr/share/fonts/X11/75dpi/' not found - ignoring
Font directory '/usr/share/fonts/X11/100dpi/' not found - ignoring
/home/epoirier/.vnc/xstartup: 1: /home/epoirier/.vnc/xstartup: Cannot fork
xrdb: Resource temporarily unavailable
xrdb: cannot run '/usr/bin/cpp -P -DHOST=thoughtful -DSERVERHOST=thoughtful -DSRVR_thoughtful -DDISPLAY_NUM=1 -DCLIENTHOST=thoughtful -DCLNT_thoughtful -DVERSION=11 -DREVISION=0 -DVENDOR="AT&T Laboratories Cambridge" -DVNDR_AT_T_Laboratories_Cambridge -DRELEASE=3332 -DNUM_SCREENS=1 -DEXT_XC_MISC -DEXT_SYNC -DEXT_MIT_SUNDRY_NONSTANDARD -DEXT_BIG_REQUESTS -DEXT_XTEST -DEXT_MIT_SHM -DEXT_SHAPE -DSCREEN_NUM=0 -DWIDTH=1024 -DHEIGHT=768 -DX_RESOLUTION=2951 -DY_RESOLUTION=2954 -DPLANES=24 -DBITS_PER_RGB=8 -DCLASS="TrueColor" -DCLASS_TrueColor=34 -DCOLOR -DCLASS_TrueColor_24=34 /home/epoirier/.Xresources'
/usr/bin/startxfce4: X server already running on display :1
xrdb: Resource temporarily unavailable
xrdb: cannot run '/usr/bin/cpp -P -DHOST=thoughtful -DSERVERHOST=thoughtful -DSRVR_thoughtful -DDISPLAY_NUM=1 -DCLIENTHOST=thoughtful -DCLNT_thoughtful -DVERSION=11 -DREVISION=0 -DVENDOR="AT&T Laboratories Cambridge" -DVNDR_AT_T_Laboratories_Cambridge -DRELEASE=3332 -DNUM_SCREENS=1 -DEXT_XC_MISC -DEXT_SYNC -DEXT_MIT_SUNDRY_NONSTANDARD -DEXT_BIG_REQUESTS -DEXT_XTEST -DEXT_MIT_SHM -DEXT_SHAPE -DSCREEN_NUM=0 -DWIDTH=1024 -DHEIGHT=768 -DX_RESOLUTION=2951 -DY_RESOLUTION=2954 -DPLANES=24 -DBITS_PER_RGB=8 -DCLASS="TrueColor" -DCLASS_TrueColor=34 -DCOLOR -DCLASS_TrueColor_24=34 /home/epoirier/.Xresources'
/usr/bin/startxfce4: X server already running on display :1
/etc/xdg/xfce4/xinitrc: 8: /etc/xdg/xfce4/xinitrc: Cannot fork
/etc/xdg/xfce4/xinitrc: 8: /etc/xdg/xfce4/xinitrc: Cannot fork
cpp: error: vfork: Resource temporarily unavailable
/usr/bin/startxfce4: X server already running on display :1
sh: 1: Cannot fork
This is the beginning of the log and it descends into more chaos from here with many different "Cannot fork" warnings. Nothing from the command line indicates that something is going wrong when starting the VNC server. Anyone have any ideas on what's going wrong here?
You are probably running out of file descriptors for the user running that process.
Check what is the current limit with ulimit -n and change accordingly.

Spark master and worker seem to run on different JVM version

In standalone mode master process uses /usr/bin/java which resolves to JVM 1.8 and worker process /usr/lib/jvm/java/bin/java which resolves to 1.7. In my Spark application I'm using some APIs introduced in 1.8.
Looking at stack trace one line that comes up is: Caused by: java.lang.NoClassDefFoundError: Could not initialize class SomeClassDefinedByMe which internally creates instance from java.time which I believe is only in JDK 1.8.
How do I force worker to use JVM 1.8?
Update:
For now I renamed /usr/lib/jvm/java/bin/java and created a link that points to /usr/bin/java. This solved the problem but still would like to know why both processes use different binary location and where is this set.
On each Worker node, edit ${SPARK_HOME}/conf/spark-env.sh and define the appropriate $JAVA_HOME e.g.
export JAVA_HOME=/usr/bin/java
That file is sourced by ${SPARK_HOME}/bin/load-spark-env.sh which is invoked by each and every Spark command-line utility:
${SPARK_HOME}/bin/spark-shell via ${SPARK_HOME}/bin/spark-class
${SPARK_HOME}/bin/spark-submit via ${SPARK_HOME}/bin/spark-class
...
${SPARK_HOME}/sbin/start-slave.sh
...
Side note: the Linux alternatives are the standard way to define which JVM is on top of your PATH...
Typical setup with a "fixed" setting, not relying on the priority set by the OpenJDK RPM install:
$ ls -AFl $(which java)
lrwxrwxrwx. 1 root root 22 Feb 15 16:06 /usr/bin/java -> /etc/alternatives/java*
$ alternatives --display java | grep -v slave
java - status is manual.
link currently points to /usr/java/jdk1.8.0_92/jre/bin/java
/usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java - priority 18091
/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java - priority 16000
/usr/java/jdk1.8.0_92/jre/bin/java - priority 18092
Current `best' version is /usr/java/jdk1.8.0_92/jre/bin/java.
...provided that $PATH is defined properly for the Linux account that launches the Spark slaves!

shared.loader="${catalina.home}/shared/classes not working on LINUX but working on WINDOWS

Does anyone know the reason why this would work in WINDOWS (tomcat 8.0.9) and not on LINUX (tomcat 6)?
I set catalina.properties (/etc/tomcat6/catalina.properties) file to:
shared.loader="${catalina.home}/shared/classes","${catalina.home}/shared/lib/*.jar"
But it is still not working...
If I run:
ps aux | grep catalina
I get:
tomcat 22199 0.1 14.2 2229892 1133948 ? Sl Sep12 7:41 /etc/alternatives/jre/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1280m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC -classpath .:/usr/lib64/jvm/java:/usr/lib64/logi-lib:/usr/share/java:/usr/share/tomcat6/lib:/usr/share/tomcat6/bin/bootstrap.jar:/usr/share/tomcat6/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat6/temp -Djava.util.logging.config.file=/usr/share/tomcat6/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start
On my windows machine all I had to do is set shared.folder in catalina.properties file and make sure I do have classes I am calling in there.
Btw, I don't have admin rights on linux machine
May be you must create the shared/classes and shared/lib folders under /usr/share/tomcat6.
In windows usually this folders are under the tomcat6 folder, but installations in Linux environment are quite different in this point.

Resources