I have written something like this in my bash file
gnome-terminal -e "bash -c \"sudo apt-get install xvfb; Xvfb :99 -ac; exec bash\""
After
Xvfb :99 -ac;
I have Xvfb running on terminal as shown in the picture. I want to stop Xvfb and return to my parent terminal after 2 seconds. How can I do this. What code I need to insert before exec command
I want to stop this
just like that:
gnome-terminal -e "Xvfb :99 -ac"
Related
Im currently writing a script which should start a docker container in a new WSL console. My question is: How do I open a new WSL console in my current working directory and execute a command in it without blocking my current console?"
I already tried "wsl -d" and "bash -c". The command "wsl" was not found and "bash -c" only esecute the given command in the current console.
Here is my script for bettter understanding:
wsl -d Ubuntu -e "sudo dockerd"
sleep 5
echo "y" | sudo docker system prune -af
wsl -d Ubuntu -e "sudo docker-compose -f docker-compose.development.yml up"
sleep 5
sudo ./connect_gremlin.sh
I am using a tool (gatk) distributed as a docker image and try to use its commands in a shell script.
I run the docker in detached mode.
sudo docker run --name my_container -d -v ~/test:/gatk/data -it broadinstitute/gatk:4.1.9.0
Then I run the commands from shell script
#!/bin/bash
docker exec my_container gatk command1
wait
docker exec my_container gatk command2
command2 needs input from command1 so I use wait, but still command2 is executed before command 1 is finished.
I also tried
#!/bin/bash
docker exec my_container gatk command1
docker wait my_container
docker exec my_container gatk command2
but then the script does not continue running after command1 is completed.
I managed to solve it. The problem was is that when I ran docker exec I did not define it to receive input from the shell. Adding -i flag to docker exec solved the problem. Here is the full solution.
I start docker in detached mode
sudo docker run --name my_container -d -v ~/test:/gatk/data -it broadinstitute/gatk:4.1.9.0
Now I can close the terminal, the docker container is up and running and I can use it in a new terminal.
I generate a bash script called myscript.sh with the following code.
#!/bin/bash
docker exec -i my_container gatk command1
wait
docker exec -i my_container gatk command2
I run the script, disown it and close the terminal.
./myscript.sh&disown;exit
You can run both commands in a single shot:
docker run image /bin/bash -c "gatk command1 && gatk command2"
Since, my product follow a micro-service architecture, I want to run multiple apps same time.
I want to open new terminal tabs and run some commands in that. Can you help me to write a bash script to perform these action. Its a repeated task I need to do daily/restart my system. I would like get it automated.
eg:
Tab1: 'cd Documents/my_app1; rails s -p 4000'
Tab2: 'cd Documents/my_app2; rails s -p 5000'
Tab3: 'cd Desktop/angular_app; yarn start --port 3000'
etc..
So, I need a script to run this with one command.
What's with the tabs?
gnome-terminal -- /bin/bash -c 'cd Documents/my_app1; rails s -p 4000'
gnome-terminal -- /bin/bash -c 'cd Documents/my_app2; rails s -p 5000'
gnome-terminal -- /bin/bash -c 'cd Desktop/angular_app; yarn start --port 3000'
I'm trying to automate my morning start up process. Often I'll start multiple running scripts that I will exit (using ctrl+c) and restart manually as needed.
So I'm looking to create a bash script that
Starts gnome-terminal
Opens some tabs and executes a number of
commands
Returns back to zsh upon exit or completion of the script so I can
manually enter more commands
Currently I have,
#!/bin/bash
gnome-terminal \
--tab -t "Server" -e "bash -ic \"cd ~/Dev/server; npm start; exec zsh\"" \
--tab -t "Framework" -e "bash -ic \"cd ~/Dev/framework; npm start; exec zsh\"" \
--tab -t "Client" -e "bash -ic \"cd ~/Dev/client; npm start; exec zsh\"" \
--tab -t "Admin" -e "bash -ic \"cd ~/Dev/admin;npm start; exec zsh\""
The problem with this solution is that tabs may or may not jump back into zsh. Sometimes 3 tabs will, sometimes one. Ideally I'd like all 4 to go back into zsh.
If anyone could help me around this, I'd be grateful.
You can take gnome-terminal out of the equation and it still won't work:
bash -ic "npm start; bash"
Press Control-C, and you won't get a shell. For bash, we can get around this problem using the --rcfile option:
bash --rcfile <(echo "npm start")
This way we don't read the real .bashrc, so since we probably want to read that, let's modify this a bit:
bash --rcfile <(echo ". ~/.bashrc; npm start")
For zsh on the other hand it doesn't work with the equivalent(?) --rcs option, but it does when started with the ZDOTDIR variable. So we create a .zshrc for each of ~/Dev/server, ~/Dev/framework, ~/Dev/client, ~/Dev/admin with the following content:
First:
. ~/.zshrc
cd ~/Dev/server
npm start
Second:
. ~/.zshrc
cd `~/Dev/framework`
npm start
etc.
Your gnome-terminal command will look like this:
gnome-terminal \
--tab "Server" -e "sh -c 'ZDOTDIR=/path/to/directory/containing/first/.zshrc'" \
--tab "Framework" -e "sh -c 'ZDOTDIR=/path/to/directory/containing/second/.zshrc'"
# etc
This script opens a gnome terminal and 4 tabs in it , but once the program finishes the tabs gets closed so i can't see the output. It doesn't happen when i run each program manually. How can keep the tab open , even when the program is finished .
gnome-terminal --tab -e "optirun yarpserver" \
--tab -e "sh -c 'sleep 20 ; optirun iCub_SIM'" \
--tab -e "sh -c 'sleep 86 ; optirun simCartesianControl'" \
--tab -e "sh -c 'sleep 116 ; optirun iKinCartesianSolver --context simCartesianControl/conf --part left_arm'" \
Not sure how to do it on the command line (man gnome-terminal doesn't seem to indicate a specific option for that, but you can start a gnome-terminal, set specific options (one of which would be "When command exits: Hold the terminal open"), and save your settings as a specific profile. There is a command-line option for selecting a specific profile to use, so that should accomplish what you want.