Open gnome-terminal on an network namespace and then run a command - linux

I'm using coreemu to to create a virtual network. I can open a terminal on a specific node with
gnome-terminal -e "vcmd -c /tmp/pycore.49330/n1 -- bash"
but I would like to open the terminal there, and then have that terminal run a command. I've played around, trying to get the terminal to open and just "echo test" but nothing I've tried works. Any help is appreciated. Thanks

Try
gnome-terminal -e "vcmd -c /tmp/pycore.49330/n1 -- bash -c 'date; read'"
to execute date.

Related

Linux script How to open new terminal and run commands in it

I am writing a script which will take users input and then run following command in new terminal.
I am working on bigger "script", but for testing I created this little version of my problem.
newtermtest.sh
okegreen='\033[92m'
while true
read -p "Input Selection: " mainmenuinput
do
#find the name of instaled terminal then run new window of it and run bash in it !
#on my computer I have instaled x-terminal-emulator: so testing on it ---- NOT WORKING YET
case $mainmenuinput in
"0")
x-terminal-emulator -e "bash -c 'nmap -sV -sC 189.55.23.174 -vvv'"
;;
"1")
path=$(pwd)
x-terminal-emulator -e "bash -c 'cd $path;touch silk.txt'"
;;
*)
break;
esac
done
echo -e "${okegreen}leaving programe..."
I have found that something like x-terminal-emulator -e {command} should work, but when I run it I have the following error and the screen just flashes.
returned message:
QDir::exists: Empty or null file name
Then I would need something to keep the terminal up, I found --noclose or -hold tags, but I can't test it util I find the working command.
Do you have some experiences with opening new terminal from bash script ?
Iam opened for any hints.
Some temporary solution which works now:
x-terminal-emulator -e 'nmap -sV -sC 189.55.23.174 -vvv'
I used just -e to execute command and with nmap it is working now.
I will figure out other commands and I will try to put it in complex script with more types of terminals.
Thanks All for suggestions.

geany does not open terminal to run my code, unless there is another terminal window is open

I am using geany version 1.36 in linux, whenever I press f5 or click on run icon in toolbar, it does not open any terminal window to run my code in. but if I open another terminal window and do nothing in it, just let it be there, all of a sudden f5 and run button work perfectly.
how can I fix this issue?
Try this:
Go to : Edit --> Preferences --> Tools --> Terminal :
Refer here For more clarification
And replace the existing lines with any of the given texts...
(Adding Terminal path here)
x-terminal-emulator -e /bin/sh %c
mate-terminal "-e /bin/sh %c"
x-terminal-emulator -e "/bin/sh %c"
xterm -e "/bin/sh %c"
xfce4-terminal -e "/bin/sh %c"
The 1st one worked for me.
For More Information about this issue Refer This Link
May you don't have the correct path for the terminal, every Linux OS comes with different terminal.
Try installing xterm:
sudo apt-get install xterm
And go to Edit>Tools>Preferences>Terminal, change the path for:
xterm -e "/bin/sh %c"

execute one command in all open tabs in a terminal

I use a script which after execution opens different tabs and connects to different servers(using ssh). Now along with that,I want to run another command (say 'pwd').So how to do that?
gnome-terminal --tab -e 'ssh user#ip1' --tab -e 'ssh user#ip2'
This opens 2 tabs and connects to corresponding ip.After ssh in every tab I want to run another command, so that there will be two tabs,and after connecting to ip it will run specified command
You need to use SSH ability to execute remote command, like this:
gnome-terminal --tab -e "ssh -A -t user#ipbridge \"ssh -t user#ip1 'pwd; /bin/bash -i'\""
Note the /bin/bash -i after the command. It is needed, because otherwise ssh will exit after the command.
Use ansible, fabric or any automation tool like any of these to do that you want. this tools allow execute a same command via ssh in multiple machines at same time in simple way.
using ansible you only need to do somthing like this
ansible <your-list-of machine> -m shell -a "your command"
example
ansible ip1 -m shell -a "echo $TERM"

Run a shell script in new terminal from current terminal

How do you run a shell script in a new terminal in Linux from a terminal like "start test.bat" in Windows, also it should be working in the console mode.
Here's a simple example to get you started:
To write a shell script, do this on your command prompt:
echo -e '#!/bin/sh\n echo "hello world"' > abc.sh
This writes:
#!/bin/sh
echo "hello world"
To a file called abc.sh
Next, you want to set it to executable by:
chmod +x abc.sh
Now, you can run it by:
./abc.sh
And you should see:
hello world
On your terminal.
To run it in a new terminal, you can do:
gnome-terminal -x ./abc.sh
or, if it's xterm:
xterm -e ./abc.sh
Here's a list of different terminal emulators.
Alternatively, you just run it in your current terminal, but background it instead by:
./abc.sh &
I came here wanting to figure out how to make a script spawn a terminal and run it self in it, so for those who want to do that I figured out this solution:
if [ ! -t 0 ]; then # script is executed outside the terminal?
# execute the script inside a terminal window with same arguments
x-terminal-emulator -e "$0" "$#"
# and abort running the rest of it
exit 0
fi
For gnome try this.
Replace ls with the command you want to run
gnome-terminal -x sh -c "ls|less"
I hope this is what you want
As of January 2020, the -e and -x option in gnome-terminal still run properly but throw out the following warnings:
For -e:
# Option “-e” is deprecated and might be removed in a later version
of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to
execute after it.
For -x:
# Option “-x” is deprecated and might be removed in a later version
of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to
execute after it.
Based on that information above, I confirmed that you can run the following two commands without receiving any warning messages:
gnome-terminal -- /bin/sh -c '<your command>'
gnome-terminal -- ./<your script>.sh
I hope this helps anyone else presently having this issue :)

Shell script statements not running one after one

I wrote a shell script that calls some other shell scripts in a new terminal window. It was working fine on my computer. its like this
#!/bin/sh
gnome-terminal -e "sh one.sh"
zenity --info --text "exed one"
gnome-terminal -e "sh 2.sh"
zenity --info --text "exed 2"
firefox "www.aurl1.com" "www.aurl2.com"
According what I understood, the script will first open a terminal and run the first script, after finishing that it will show the zenity then run two in new terminal then show zenity like that. But when the same was exed on another computer, the script is not following this order. It simply opens all terminal side by side not waiting one to finish and showing the dialogues together. Why is this problem ? Thanks in advance.
It used to be that gnome-terminal would run each terminal in its own process. But now gnome-terminal checks on startup if there is already a gnome-terminal process running, and if so, tells the existing terminal process to open a new window with the given arguments. There is no problem with your script: it is waiting for each process to finish in turn, it is just that gnome-terminal is exiting immediately after passing off its work to a different process.
According to man gnome-terminal, you can use the --disable-factory option to disable this behaviour, and run each command in its own process.
Try this:
gnome-terminal --disable-factory -e 'sh -c "echo hi && sleep 10"'
echo now you can run script 2
Run them like this:
gnome-terminal -e "sh one.sh" ; zenity --info --text "exed one" ; gnome-terminal -e "sh 2.sh" ; zenity --info --text "exed 2"
What the comma does is it tells the shell to execute the first command, wait for it to finish and only then move on to the next. Otherwise, the behavior you described is normal, it parses the lines one by one, without waiting for anything.

Resources