ConEmu: Open a new shell of the same configuration with a GuiMacro - conemu

How can I open up a new ConEmu shell of the same configuration?
For example, currently I open a new git bash shell with this GuiMacro:
Shell("new_console", "{Bash::Git bash}", "", "%CD%")
How can I make this more generic? So that if I am in a git bash shell, it will use {Bash::Git bash}; but if I am in a cmd prompt, it will use {Shells::cmd}

Related

how to run multiple command inside other terminal using batch file

i am using nvs, and there is a nvs command line using which i can change my node version.
currently i am using .bat file from Desktop and then go to nvs terminal
cd C:\nvs
start "C:\nvs\nvs.cmd"
this opens the terminal, and then i need to type more commands inside nvs terminal like
nvs use node/10.16.3/x64
cd ../code/api
node -v
code .
i need to automate this and all the executables to be part of the .bat file.
i tried using /c or /k to concatenate the commands. but the terminal closes before executing anything. how to run these commands as a part of batch file together.

How do I execute cmd commands through a bat file?

I need to create a .bat to put together with my setup system to install a network driver, but I have some difficulties in creating the bat.
This .bat needs:
execute a cmd with administrator privileges
run this command: netcfg.exe -v -l networkbll_lwf.inf -c s -i nt_networkbll
exit
The folder for all files location is: c:\Windows\System\Drivers.
You might have to use another batch file first to launch the second with admin rights.
In the first use
runas /noprofile /user:mymachine\administrator batchfilename.bat
PAUSE
and write the needed command in another bat file

how to run pass docker terminal commands using .bat file

I Want to invoke docker compose using bat file.I have tried to invoke using the following but its not executing the commands.
this is my .bat file
echo on
cd C:\Program Files\Docker Toolbox\
start start.sh cd desktop
cd test
docker-compose up
Is there any other way to execute docker commands using bat file.or any other file.
A batch file is a script file. A script needs an interpreter. For a batch file the interpreter is cmd.exe – the Windows command interpreter.
A *.sh file is also a script which needs an interpreter. The interpreter is on Unix/Linux systems sh, bash, ksh, ... which are also executables but without file extension .exe because on Unix/Linux executables usually do not have a file extension.
On Windows there is no interpreter installed by default for Unix/Linux shell scripts. If start start.sh works at all than because of having installed a shell interpreter on Windows which has been registered in Windows registry as application for opening *.sh files which means interpreting the commands in the shell script file by started application.
But commands in a batch script interpreted by cmd.exe and executed within a Windows command environment can't be executed in shell environment of the shell interpreter.
start start.sh starts a new process running parallel to the Windows command process created for execution of the batch file. The batch file processing immediately continues after this line with executing the next command in command process while the shell interpreter process interprets parallel the commands in start.sh.
So what you need here is a batch file which creates a shell script to call start.sh and executes other shell commands in shell environment by shell interpreter.
The batch code below might work. It is not tested by me as I don't have Docker Toolbox nor any shell interpreter installed on my Windows machine.
#echo off
set "ShellScriptFile=%TEMP%\%~n0.sh"
( echo start.sh
echo cd desktop/test
echo docker-compose up
) >"%ShellScriptFile%"
start "Docker Compose" /D"%ProgramFiles%\Docker Toolbox" /wait "%ShellScriptFile%"
del "%ShellScriptFile%"
set "ShellScriptFile="
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /? ... explains %~n0 (name of batch file without file extension and path)
del /?
echo /?
set /?
start /?
Read also the Microsoft article about Using Command Redirection Operators for an explanation of redirection operator > used here to create the shell script to execute with the 3 lines:
start.sh
cd desktop/test
docker-compose up
Those 3 lines are executed in the shell environment by shell script interpreter.
To run docker-compose via a bat file,
1. create a bat file eg run-docker-compose-up.bat
cd c:\docker
docker-compose up -d
pause
c:\docker is where I placed my docker-compose.yml
-d run containers in the background docker compose up docs
docker-compose must run as Administrator.
While a bat file itself cannot be marked as run as Administrator, you can either
right click on the bat file and choose 'Run as administrator'
or create a shortcut to the bat file and mark it as run as Administrator
(right click on shortcut, choose Properties, choose Advance, choose 'Run as administrator')
As I solved this problem, in a docker-compose case:
Go to your docker-compose.yml folder
On that, create a batchfile, such as: mydockerbatchfile.bat, using notepad (or other)
On this file, type your docker commands sequence', such as:
echo on
docker-compose down
docker container prune --force
docker system prune --volumes --force
docker image rm xxx/web-api
docker system df
docker image ls
pause
OBS: the commando pause will allow you check the results execution, in the screen)
Save -> make sure you saved in batch format/extension (mydockerbatchfile .bat)
In your windows desktop, create a ShortCut for the 'item 3 batch-file' (here - do not set the shortcut to "run as administrator")

Automating putty with .bat file [duplicate]

I want to run a few shell commands every time I SSH to a server via PuTTY. I'm connecting to a production web server managed by someone else, and I don't want to store my own scripts there.
I see the option Connection > SSH > Remote Command, but if I put my initialization commands there, after starting the session, it closes immediately after the commands execute. How can I run the Remote Command, and then keep the session open so I can continue using it?
The SSH session closes (and PuTTY with it) as soon as the command finishes. By default the "command" is a shell. As you have overridden this default "command" and yet you want to run the shell nevertheless, you have to explicitly execute the shell yourself:
my-command ; /bin/bash
See also Executing a specific command on the server.
One option to go is set up your putty remote command like this:
ls > dir.ls & /bin/bash
In this example command you want to run is "ls > dir.ls" what creates file dir.ls with content of directory listing.
And as you want to leave shell open you can add aditional command "/bin/bash" or any other shell of your choice.

putty from a batch file and a script?

I have a batch file that opens putty just fine.
c:\putty.exe root#192.168.12.34 -pw boyhowdy. But to make this work for me I need to understand how to include a script of a command so it will run under the putty tool. Like mount –o remount,rw / . Or is this something I can do with a tool called pscp. I am a nube to these tools and really could use some guideance. I have a bunck of these scripts and would really like to automate them. Thankyou
If your goal is to execute shell commands remotely through putty, you should probably look at plink (putty without the gui, in other words an ssh client for windows) and then apply the standard here-doc techniques to plink.
plink is part of the putty collection and is also downloadable from the same page as putty.
If you want to execute a local script you would use
plink user#host -m local_script.sh
For instance. Assuming you're running on some Windows box (fyi the putty suite also runs on Linux) and want to execute a batch of commands on some remote box you would create a shell script on your local machine (say mount.sh) and run it like this:
C:\> type mount.sh
whoami
hostname
/usr/sbin/mount -t iso9660 -o ro /dev/cdrom /mnt
/usr/sbin/mount | grep mnt
C:\> plink remoteuser#remotehost -pw secret -m mount.sh
remoteuser
remotehost
/dev/cdrom on /mnt type iso9660 (ro)
Also, it's probably better to copy your public key over so that the password is not coded in some batch file.
Finally, be aware that not all environment variable defined in an interactive shell process will be available in the remote shell process. You might need to 'source' some profile script at the beginning of your script.

Resources