I want to use a command line tool to attach a remote container. I tried this command (see below), but it's of no use. Does anyone know the correct command?
code --folder-uri vscode-remote://dev-container+4aaf623ee98a52fa311226a2c619be19addfa221c090b9a3bc37e7cba03a7fce/easycv
That string of characters after dev-container+ is an ascii path to your dev container folder encoded in hexadecimal.
To open a folder in a container you can use the following style command:
code --folder-uri=vscode-remote://dev-container%2B{path-in-hex}/{path-inside-container}
For example to open the folder /workspaces/test in the development container located in /Users/jkells/projects/vscode-devcontainer I use the following CLI command.
code --folder-uri=vscode-remote://dev-container%2B2f55736572732f6a6b656c6c732f70726f6a656374732f7673636f64652d646576636f6e7461696e6572/workspaces/test
To convert the string /Users/jkells/projects/vscode-devcontainer into the hexadecimal 2f55736572732f6a6b656c6c732f70726f6a656374732f7673636f64652d646576636f6e7461696e6572 you can use the following command
printf /Users/jkells/projects/vscode-devcontainer | od -A n -t x1 | tr -d '[\n\t ]'
To automate this, I created this cross-plattform-ish solution:
https://github.com/geircode/vscode-attach-to-container-script
This solution creates the hex based on the name of the running container.
Windows CMD script:
docker run --rm geircode/string_to_hex bash string_to_hex.bash "<container_name>" > vscode_remote_hex.txt
set /p vscode_remote_hex=<vscode_remote_hex.txt
code --folder-uri=vscode-remote://attached-container+%vscode_remote_hex%/app
This shell script does the job:
#!/usr/bin/env bash
case $# in
1) ;;
*) echo "Usage: code-remote-container <directory>"; exit 1 ;;
esac
dir=`echo $(cd $1 && pwd)`
hex=`printf ${dir} | od -A n -t x1 | tr -d '[\n\t ]'`
base=`basename ${dir}`
code --folder-uri="vscode-remote://dev-container%2B${hex}/workspaces/${base}"
I have saved it under the name code-remote-container, which then e.g. can be used
as:
code-remote-container .
which would open the current directory in the remote container.
Obviously this expects that the remote container has already been setup for vsc.
Related
I need to expand variables before running the SCP command as a result I can't use single quote. If I run the script using double quotes in Powershell ISE it works fine.
But doesn't work if I run the script through command prompt.
I'm using zabbix to run the script which calls the script as [cmd /C "powershell -NoProfile -ExecutionPolicy Bypass -File .\myscript.ps1"]
Here is the code that needs to run SCP using Cygwin bash.
if ((test-path "$zipFile"))
{
C:\cygwin\bin\bash.exe -l "set -x; scp /cygdrive/e/logs/$foldername/dir1/$foldername.zip root#10.10.10.10:~/"
}
Output:
/usr/bin/bash: set -x; /cygdrive/e/logs/myfolder/dir1/server.zip root#10.10.10.10:~/: No such file or directory
If I run the same command above in Cygwin manually it works.
I even tried to use bash -l -c but then the SSH session is stuck maybe because the root#10.10.10.10 becomes $1 according to the documentation.
Documentation link
-c If the -c option is present, then commands are read from
the first non-option argument command_string. If there are
arguments after the command_string, the first argument is
assigned to $0 and any remaining arguments are assigned to
the positional parameters. The assignment to $0 sets the
name of the shell, which is used in warning and error
messages.
Figured it out. It was halting when using bash -c was due to StrictHostKeyChecking, the known hosts thing (where you get a prompt to type yes/no). I set the -v switch to SCP and it showed me the Debug logs where it was halting.
Had to set scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null options.
The complete line now looks like the following:
c:\$cygwin_folder\bin\bash.exe -c ("/usr/bin/scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -v -i /cygdrive/c/cygwin/home/myuser/.ssh/id_rsa /cygdrive/e/logs/$foldername/dir1/$foldername.zip root#10.10.10.10:~/")
My docker-compose.yml looks like this
services:
my-service:
image: ${PYTHON_IMAGE}:${PY_VERSION}
these ENV variables are declared in WSL, however when I use VS code remote container to launch the development in the container, it will fail, I tried using WSLENV to assign the variables and tested within a session between WSL and Windows, the variables are properly shared but still couldnt get the variables assigned when the container is created/build by VSCode
Appreciate your response
Thanks
Right now I get it working using
WLSENV
added the following line to .bashrc
export WSLENV=$WSLENV:VAR_NODE_IMAGE_NAME/u:VAR_NODE_VERSION/u
cmd.exe /C set | grep '^VAR' | tr '=' ' ' | awk '{printf "SETX %s %s\n", $1, $2}' | cmd.exe >> /dev/null
this will add the env vars to Windows when I launch my terminal
On RHEL, the below command works:
psql -h hostname -U username -p port_no -d database -f /tmp/myfile.sql &> logfile01.txt
On FreeBSD, this throws error:
"Invalid null command"
Please suggest.
If you use this only on the command line then there is no need to change the shell.
To redirect stdout and stderr to a file in C-Shell synthax simply use ">& filename".
Different story is, if you want to write shell scripts. Bourne Shell and it's clones (like i.e. Bash) are better suited for writing script. See this Unix FAQ "Csh Programming Considered Harmful": http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
This redirection works in bash
&> logfile01.txt
, but it does not work in csh which is the default shell in FreeBSD.
# set | grep shell
shell /bin/csh
# ls -la &> logfile01.txt
Invalid null command.
Bash is not installed by default. You can install it
pkg install bash
and configure it as the default shell.
I am running a perl script from Nagios to check some files for certain characteristics on a windows machine. When I run the script from Nagios it responds with a result of:
UNKNOWN ERROR - execution of LANG=C ls -l resulted in an error 32512 -
My Code is from this GitHub with a single modification of line 168 so I can use it with windows:
use lib 'C$\Progra~1\Nagios\NRDS_Win\plugins';
The odd thing is the program actually outputs the expected result from the command line on the windows machine.
Here is the command:
check_files.pl -D c:\logs -F Health.log -a '~,300'
Here is an example:
CRITICAL - Health.log is 10703 (more than 300) seconds old - 1
Health.log files found
I modified line that defined LANG=C ls -l in the code but now i just get:
UNKNOWN ERROR - could not execute ls -l - No such file or directory
ls is unix command and by default there is no such command in windows.
If you need it, you can install it e.g. from GNU CoreUtils
You also need to change shell command on line 639 from LANG=C ls -l to just ls -l because in windows you can't set environment variables like that.
I try to open annotation file from mimic2 db for patient a40017 that called a40017.alM.
I have this link for the data: http://www.physionet.org/pn5/mimic2db/a40017/
and I don't find the exact command in Cygwin that export the file to csv or text.
I try to use this command:
rdann -r mimic2db/a40017/a40017 -f 0 -t 216647.728 -a alM -v >annotations.txt
but I got an empty file
Is anyone know how can I do that?
Thanks,
Gal
Anwering myself. Rdann is a mingw32/64 program
https://physionet.org/physiotools/binaries/windows/
If you are in the same directory of the program and it is not in the PATH you need to run:
./rdann -r mimic2db/a40017/a40017 -f 0 -t 216647.728 -a alM -v
or
/<fullpath>/rdann ...