Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Can't pass a variable representing the output of lsb_release to a docker dontainer Post 303019913 by James Ray on Tuesday 10th of July 2018 05:32:39 AM
Old 07-10-2018
Can't pass a variable representing the output of lsb_release to a docker dontainer

I don't know why, but the rendering of my code mucks up the spacing and indentation, despite being correct in the original file. I'm having issues getting the following script to run (specifically the nested script at the end of the docker command near the end of the script; I think I'm not passing the `lsb_release` variable correctly as an argument to the called `create_rpc_rs.sh` script, but I don't know how to correctly do so):

Code:
#!/bin/sh

# This script regenerates the `src/rpc_proto.rs` file from `rpc.proto`.

lsb_release=$(lsb_release -si);
echo"$lsb_release"
echo"Checking if docker is installed."
if docker --version | grep -q "Docker version";then
echo"Confirmed that docker is installed."
else
echo"Docker is not installed; attempting to install now."
if [[ "$lsb_release"=*Linux* ]];then
case"$lsb_release"in*Ubuntu*)
            apt-get update;
            apt-get install -y docker;;
*Manjaro*) sudo pacman -S --needed docker;;
*)
echo"installation for Docker is not configured for \
            your OS, please install manually and make a pull \
            request to install in this script for your OS">&2;
exit 1;;
esac;
fi
fi

echo"Checking that docker is running."
if systemctl status docker | grep -q 'Active: inactive (dead)';then
echo"docker is not running; starting docker now."
    systemctl start docker
else
echo"Confirmed that docker is running."
fi

docker run --rm -v "$(pwd)":/usr/code:z -w /usr/code rust \
    /bin/bash -c "sh create_rpc_rs.sh $lsb_release"

mv -f rpc.rs ./src/rpc_proto.rs

This is create_rpc_rs.sh:


Code:
#!/bin/sh

echo"Installing protobuf if not already installed."
if [[ $1=*Linux* ]] ;then
case$1in*Ubuntu*)
        apt-get update;
        apt-get install -y protobuf-compiler;;
*Manjaro*) sudo pacman -S --needed protobuf;;
*)
echo"installation for protobuf is not configured for \
            your OS, please install manually and make a pull request;"
# exit 1;;
esac;
fi
echo"installing protobuf";
cargo install --version 1 protobuf;
echo"Producing rpc.rs via protoc and rpc.proto"
 protoc --rust_out . rpc.proto

This is the output when running `./regen_proto_structs.sh`, as you can see, `lsb_release` is not found, and I don't know how to correctly pass it Ii.e. the output of lsb_release -si on the computer that docker is runnning on, to the docker container.:

Code:
$ ./regen_structs_proto1.sh
Checking if docker is installed.
Confirmed that docker is installed.
Checking that docker is running.
Confirmed that docker is running.
Installing protobuf if not already installed.
create_rpc_rs.sh: 4: create_rpc_rs.sh: [[: not found
installing protobuf
    Updating registry `https://github.com/rust-lang/crates.io-index`

Unfortunately I posted this at a bad time as I need to stop working for the day.

Last edited by James Ray; 07-10-2018 at 08:57 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[csh] How to capture output from a command and pass it on to a variable?

Hi there! I'm trying to write a script that will capture output from a command and assign it to a variable. Let's say, for example, I'd like to catch from inside the script whatever the following command outputs: ls *.aaa and put it into a variable "listoffiles". What I tried was: set... (3 Replies)
Discussion started by: machinogodzilla
3 Replies

2. Shell Programming and Scripting

Representing dir path for copy through env variable

Hello , i am on linux, and im trying to figure out why my cp command cant copy one file. I am trying to use variable in which i stored path to location where is file i wish to copy. $ echo $ORA_ALERT_LOG /u01/app/oracle/diag/rdbms/ring11/ring11/trace $ $ $ pwd /home/oracle $ cp -p... (2 Replies)
Discussion started by: tonijel
2 Replies

3. Shell Programming and Scripting

How to pass a function with a variable parameter into another variable?

Hello again :) Am currently trying to write a function which will delete a record from a file. The code currently looks as such: function deleteRecord() { clear read -p "Please enter the ID of the record you wish to remove: " strID ... (2 Replies)
Discussion started by: U_C_Dispatj
2 Replies

4. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

5. Shell Programming and Scripting

cannot pass a echo output to a variable in bash

Hi, I have a problem with passing a echo output into a variable in bash file='1990.tar' NAME='echo $file | cut -d '.' -f1'; echo $NAME the result is echo $file | cut -d . -f1 however with this one,#!/bin/bash file='1990.tar' echo $file | cut -d '.' -f1 the result is what I... (2 Replies)
Discussion started by: 1988PF
2 Replies

6. UNIX for Beginners Questions & Answers

Need to pass variable in a command and assign value to a variable

Hello All, Hope you're doing well ! I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted. header_date_14=$(m_dump... (8 Replies)
Discussion started by: ektubbe
8 Replies

7. Homework & Coursework Questions

How to Dynamically Pass Parameter to plsql Function & Capture its Output Value in a Shell Variable?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 2. Relevant commands, code, scripts, algorithms: #! /bin/ksh v="ORG_ID" ... (2 Replies)
Discussion started by: sujitdas2104
2 Replies

8. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

9. Docker

Docker learning Phase-I

Hello All, I had recently learnt a bit of Docker(which provides containerization process). Here are some of my learning points from it. Let us start first with very basic question: What is Docker: Docker is a platform for sysadmins and developers to DEPLOY, DEVELOP and RUN applications ... (7 Replies)
Discussion started by: RavinderSingh13
7 Replies
All times are GMT -4. The time now is 04:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy