logo
Tags down

shadow

Not able to initialize variables when running as another user in shell


By : user2175632
Date : October 14 2020, 08:10 PM
this one helps. Expansion happens on the original user side, not on the side after sudo.
code :
sudo -H -u user1 bash <<EOF
presentdir="$(pwd)"
echo "$presentdir"
EOF
sudo -H -u user1 bash <<EOF
presentdir="/home/orinal_user"
echo ""
EOF
sudo -H -u user1 bash -c 'presentdir="$(pwd)"; echo "$presentdir"'
sudo -H -u user1 bash <<EOF
presentdir="\"\$(pwd)\""
echo "\"\$presentdir\""
EOF
sudo -H -u user1 bash <<"EOF"
presentdir="$(pwd)"
echo "$presentdir"
EOF


Share : facebook icon twitter icon

Is there a way to read all key-value pairs in the JSON file and then initialize all variables accordingly in shell?


By : Anjali Mishra
Date : March 29 2020, 07:55 AM
I hope this helps . You can loop over the key/value pairs and use declare to create variable names dynamically.
code :
while read -r name value; do
    declare "$name=$value"
done < <(jq -r 'to_entries[] | "\(.key) \(.value)"' arguments.json)

Running a shell script to initialize pods in kubernetes (initializing my db cluster)


By : Priyanka
Date : March 29 2020, 07:55 AM
hope this fix your issue I finally decided to take the approach of creating a config file with the script we want to run and then call this configmap from inside the volume.
this is a short explanation:
code :
apiVersion: v1
kind: Pod
metadata:
  name: "{{.Values.container.name.primary}}"
  labels:
    name: "{{.Values.container.name.primary}}"
spec:
  securityContext:
    fsGroup: 26
  restartPolicy: {{default "Always" .Values.restartPolicy}}

  containers:
  - name: {{.Values.container.name.primary}}
    image: "{{.Values.image.repository}}/{{.Values.image.container}}:{{.Values.image.tag}}"
    ports:
    - containerPort: {{.Values.container.port}}
    env:
    - name: PGHOST
      value: /tmp
    - name: PG_PRIMARY_USER
      value: primaryuser
    - name: PG_MODE
      value: primary
    resources:
      requests:
        cpu: {{ .Values.resources.cpu }}
        memory: {{ .Values.resources.memory }}
    volumeMounts:
    - mountPath: /pgconf
      name: init-script
      readOnly: true
  volumes:
  - name: init-script
    configMap:
      name: postgres-init-script-configmap
apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-init-script-configmap
data:
  setup.sql: |-
    CREATE USER david WITH PASSWORD 'david';

Can the .bash_profile used to initialize a shell be recovered from a running instance?


By : Vivek Badmaliya
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I was an idiot and accidentally overwrote my bash_profile. by using > instead of >>, I also don't have any backups of it which won't happen if this works. , To dump shell variables and functions, run:
code :
declare -p
declare -fp
alias -p

How can I initialize a Docker container with the result of running a shell script?


By : Rob Carlan
Date : March 29 2020, 07:55 AM
help you fix your problem The reason this is not working (but does work when you run the steps you described in bash) is because each step of a Dockerfile runs an isolated process - the environment is not shared between steps.
If you need to set environment variable in a Dockerfile the normal way to do so would be using the ENV directive. With this you can do something like this to set an environment variable:
code :
ENV JAVA_OPTS="-..."
ENV JAVA_OPTS="-..." OTHER_VAR="..."
#! /bin/sh

set -e

/usr/local/tomcat/bin/setEnv.sh         # Call this however you did in your bash session where it worked
/usr/local/tomcat/bin/startup.sh "$@"

Initialize PySpark shell by running a script in my Linux terminal (Spark Version 2.4.4)


By : seetharamanj
Date : March 29 2020, 07:55 AM
will help you SparkSession is an unified functionality, no need to initialize again.
Coming to other part of import the functionality by default, you can use this
code :
>>> execfile("<some name>.py")
vi scrp.py

df1 = sc.parallelize([[1,2,3], [2,3,4]]).toDF(("a", "b", "c"))
df1.show()

from pyspark.sql.functions import *
>>> execfile("scrp.py")
+---+---+---+
|  a|  b|  c|
+---+---+---+
|  1|  2|  3|
|  2|  3|  4|
+---+---+---+

>>> df1.show()
+---+---+---+
|  a|  b|  c|
+---+---+---+
|  1|  2|  3|
|  2|  3|  4|
+---+---+---+

>>> df1.withColumn("news", when(col("a") > 1, "t")).show()
+---+---+---+----+
|  a|  b|  c|news|
+---+---+---+----+
|  1|  2|  3|null|
|  2|  3|  4|   t|
+---+---+---+----+
shadow
Privacy Policy - Terms - Contact Us © voile276.org