I need to copy a pdf file from the bash command line. I have trouble using cp. An error message appears. If I can copy it, I am hoping that it is stored as a variable. That's all.
enter image description here Here's an image file of the example for more simple and detailed situation.
1) you typed "cd" into the command line, not "cp"
2) to use 'cp' you need to type [ cp (inputfile) (outputfile) ]
Related
I'm trying to perform automation process using docker.
I have couple of files in my local system and these files will be used inside of a container, so my code so far looks like the following :
FROM docker_image_on_the_internet:stable
COPY . /root/
# Now I have a command that will execute the copied files
CMD cmd1 --opt-dir --file-copied
# After executing cmd1, a file will be generated inside of the container, the file name consists of timestamp and a public key, example : UTC--2022-03-07T10-53-08.532008168Z--84e9ed8d078f2bdc71e4ca9a322d2f4222c9b7b7
# Now I have another command that will be executed USING THE FILENAME CREATED
CMD cmd2 --opt-dir --file-created-inside-the-container
Is there any way to get the created file from the container and use it directly in cmd2 line? because this file is a JSON file that looks like this :
File name : UTC--2022-03-07T10-53-08.532008168Z--84e9ed8d078f2bdc71e4ca9a322d2f4222c9b7b7
File content :
{"address":"84e9ed8d078f2bdc71e4ca9a322d2f4222c9b7b7","crypto":{"cipher":"aes-128-ctr","ciphertext":"a14e5429363ce09903aeccf1afa9ea49a02a4974e0fa032d14f7077ceae21588","cipherparams":{"iv":"a214bcb73a74554bb9be59df158c4d4e"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"d933d92a667eec528299c354e1efe0da730cea2a53a082dbeafc9ed70ca40a71"},"mac":"803325a434a6541c5d93d15f11762d2907e1da1c6520fc33632934565822733d"},"id":"694ca50f-3ae9-4520-94f9-a80003c3f95f","version":3}
Because I need the address public key to be executed as an option in the CMD2, and my local files already contains a .ENV file which supposedly contains that variable (need to copy the address and added to the .env file - or execute it directly in the cmd2 as a string option without using environment variables)
Is there anyway I can achieve this ?
Thanks in advance !
You could create the file elsewhere select him using UTC--* (since this would be the only matching file), move him to the correct destination if you want at the end of the process.
By using jq you could extract this variable: ADDRESS=$(cat <your_file> | jq -r .address) and then use it.
I have a very simple dockerfile which i have written but unfortunately, it is failing while executing below command in dockerfile:-
RUN ["cp -r", "node_modules/dir1/test/*", "/app"]
Below is the Error message which i get:-
OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"cp -r\": executable file not found in $PATH": unknown
I have also tried using "mv" command instead of "cp" but with no success.
I don't want to move the complete folder but all the content of folder. As said if i execute below command it works but, it moves the directory:-
RUN ["cp -r", "node_modules/dir1/test", "/app"]
Any Suggestions.? I have tried looking into many questions but, couldnt find a concrete explanation and the answer on how we can do it.?
Thanks,
Vishesh.
Internally in Unix-like operating systems, commands are broken up into "words". When you use the JSON-array syntax for RUN, ENTRYPOINT, and CMD directives, you're explicitly specifying what the words are, and they're not further processed split up.
In particular when you run
RUN ["cp -r", "node_modules/dir1/test/*", "/app"]
it looks for a command named cp -r in the usual places, where the command name includes a space and a hyphen. It won't find /bin/cp which doesn't have a space and a hyphen and there isn't a /bin/cp\ -r. If this were to work, it would also pass its first argument containing a * in the filename, which will also fail.
The easiest solution here is to not use the JSON-array form. This will implicitly run a shell (the command is wrapped in /bin/sh -c) which will split words and expand globs for you.
RUN cp -r node_modules/dir1/test/* /app
If you didn't need the wildcard, you need to manually split cp and -r into separate words
RUN ["cp", "-r", "node_modules/dir1/test", "/app"]
First, you need to check if the cp command is available. Once it's available you need to add /. for copying the content only.
RUN ["cp -r", "node_modules/dir1/test/.", "/app/"]
Snapshot from the documentation.
I am trying to follow the 2 steps mentioned below:
1) Downloaded source code of
https://sourceforge.net/projects/hunspell/files/Hyphen/2.8/hyphen-2.8.8.tar.gz/download
2) Compiled it and you will get binary named example:
hyphen-2.8.8$ ./example ~/dev/smc/hyphenation/hi_IN/hyph_hi_IN.dic
~/hi_sample.text
I have downloaded and uncompressed the tar file. My question is how to create a dockerfile to automate this?
There are only 3 commands involved:
./configure
make all-recursive
make install
I can select the official python image as a base container. But how do I write the commands in a docker file?
You can do that with a RUN command:
FROM python:<version number here>
RUN ./configure && make-recursive && make install
CMD ['<some command here>']
what you use for <some command here> depends on what the image is meant to do. Remember that docker containers only run as long as that command is executing, so if you put the configure/make/install steps in a script and use that as your entry point, it's going to build your program, and then the container will halt.
Also you need to get the downloaded files into the container. That can be done using a COPY or an ADD directive (before the RUN of course). If you have the tar.gz file saved locally, then ADD will both copy the file into the container and expand it into a directory automatically. COPY will not expand it, so if you do that, you'll need to add a tar -zxvf or similar to the RUN.
If you want to download the file directly into the container, that could be done with ADD <source URL>, but in that case it won't expand it, so you'll have to do that in the RUN. COPY doesn't allow sourcing from a URL. This post explains COPY vs ADD in more detail.
You can have the three commands in a shell script and then use the following docker commands
COPY ./<path to your script>/<script-name>.sh /
ENTRYPOINT ["/<script-name>.sh"]
CMD ["run"]
For reference, you can create your docker file as they have created for one of the projects I worked on Apache Artemis Active Mq:
https://github.com/apache/activemq-artemis/blob/master/artemis-docker/Dockerfile-ubuntu
I'm following this tutorial and when I get to the part where I call:
cp /tf_files/stripped_retrained_graph.pb bazel-bin/tensorflow/examples/android/assets/stripped_output_graph.pb
and
cp /tf_files/retrained_labels.txt bin/tensorflow/examples/android/assets/imagenet_comp_graph_label_strings.txt
They both say "No such file or directory".
As you can see in this image I can cd to the tf_files folder and see that the files are there.
I can also cd to /tensorflow/tensorflow/examples/android/assets and call ls which shows there's just a BUILD file there.
In the cp command is there supposed to already be a stripped_output_graph.pb file in the destination which gets replaced? Or is it meant to just be creating a new file there?
Is there some way of doing cp [source] [current directory] rather than specifying the destination as a path?
I've tried removing the file path part in hope that it just uses the source filename but that doesn't work.
Calling
cp /tf_files/stripped_retrained_graph.pb /tensorflow/tensorflow/examples/android/assets/stripped_output_graph.pb
and
cp /tf_files/retrained_labels.txt /tensorflow/tensorflow/examples/android/assets/imagenet_comp_graph_label_strings.txt
finally worked, wasn’t at all obvious that I’d have to change the destination path or what it should be though.
Also I accidentally saved a file as .p rather than .pb but managed to remove it using $ docker exec <container> rm -rf /tensorflow/tensorflow/examples/android/asset
s/stripped_output_graph.p
Now I managed to copy the files in correctly, but then when I installed the app it was still just running the regular demo app.
Not sure why it didn’t work, so frustrating.
When I rebuilt it after copying the files in I got these conflict messages
Are these normal to have?
It looks like maybe a different labels file is taking priority over mine, how can I reach the external/inception5h/imagenet_comp_graph_label_strings.txt file to delete it so my file is used instead?
Does the “external” part mean that I can’t actually access it?
I want to do the following commands in ruby.
ssh into another computer using ssh example#example
set source file source ~/.profile
cd to/some/folder
call my shell script with parameters, a json formatted string ,./my_script.sh my_hash.to_json
However I am facing these problems:
I call them in one line using backticks, it works, but it is a very bad practice in my opinion because it is not readable nor it is maintainable.
On the other hand, when I call my_hash.to_json, the resulted string has non-escaped double quotes, How do I escape them?
I would recommend to view this tutorial for ssh with ruby. then make a shell script and move it to server and then execute like a single command.
create a single shell script file for example script1 and then execute it at once instead of executing each command individually.
open file script1 using any editor.
copy all commands to script1 (each command in new line).
script1 file should look like this
#!/bin/bash
ssh example#example
source ~/.profile
cd to/some/folder
save file
make this file executable using chmod +x script
execute it in ruby like this [backtick]./script1[backtick]
note: copy script1 to usr/bin to avoid "./" and then try command only script1.
Reference for passing arguments in shell script is here.