Linux shell scripting for different tabs - linux

I want a script,which after executing will open multiple tabs and a specified command will run on every tab.Basically that command is ssh i.e. for connecting to other machines.

you can try something like this;
gnome-terminal --tab --title "server1" -x bash -c "ssh -t user1#host1 'nohup yourCommand'" --tab --title "server2" -x bash -c "ssh -t user2#host2 'nohup yourCommand'"

Related

Gnome terminal doesn't recognise commands when started from startup-applications with .sh file

I am trying to use an .sh script to start a terminal when ubuntu boots. Gnome-terminal successfully starts up but when commands start executing such as (roscore, roslaunch or rosrun) it displays an error as follows: "bash: roslaunch command not found". Is there any way to fix this problem or any other way to start launch files of ROS with a visible terminal at start?
This is how my .sh file looks like
#!/bin/bash
gnome-terminal --geometry=40x40 \
--tab --title="roscore" -e "bash -c \"source ~/.bashrc;roscore;exec bash\"" \
--tab --title="navigation" -e "bash -c \"sleep 38;roslaunch navigation.launch;exec bash\"" \
--tab --title="robot" -e "bash -c \"sleep 28;roslaunch robot_config.launch;exec bash\""
Are you sourcing ros setup.bash file (source /opt/ros/$ROS_DISTRO/setup.bash)? If not just add it to ~/.bashrc file

In linux terminal how to open a ssh session and type bash command inside the ssh session using gnome-terminal

Problem:
I tried Using the Below commands but no use, it only ssh to the machine but not execute the command "bash" after connected to ssh target.
Trails:
Method #1 : gnome-terminal --tab -t "NASIR-QEMU" -e "/bin/bash -c 'ssh -t 10.10.10.1;bash;bash'"
Method #2 : gnome-terminal --tab -t "NASIR-QEMU" -e "/bin/bash -c 'ssh -t 10.10.10.1;bash'"
Method #3 : gnome-terminal --tab -t "NASIR-QEMU" -e "/bin/bash -c 'ssh 10.10.10.1 ;bash'"
Method #4 : gnome-terminal --tab -t "NASIR-QEMU" -e 'ssh -t 10.10.10.1;bash'
Method #5 : gnome-terminal --tab -t "NASIR-QEMU" -e 'ssh -t 10.10.10.1"bash;bash"'
this method#4 #5 closes my open terminal
Note: "a fake IP (10.10.10.1) is entered for posting example only so pls dont get misleaded"
Help is highly appreciated!!!
Thanks
use ssh 10.10.10.1 /bin/bash as you need to specify the absolute path.
try doing echo to test if this works since you will at least be able to see some output as the ssh login also logs into a terminal- the very same command that you are executing.. i.e. bash. so you may not be able to distinguish

Bash script with multiple sudo commands in tabs

I have a bash script that opens a mate-terminal with 3 tabs, each tab having a command that requires sudo. The problem is that I have to put in my sudo password on each of the 3 tabs, which is not ideal. Can I make it so I only have put in my sudo password once? Basically, I want to double click the shell script, put in my sudo password once, and have all 3 commands execute. How can I do this? This script looks like this:
#!/bin/sh
mate-terminal \
--tab -e "sudo /sbin/mgetty -s 115200 -D /dev/ttyUSB0" \
--tab -e "sudo tail -f /var/log/mgetty/mg_ttyUSB0.log" \
--tab -e "sudo tail -f /var/log/messages"

Ksh script: How to remain in ssh and continue the script

So for my script I want to ssh into a remote host and remain in the remote host after the script ends and also have the directory changed to match the remote host when the script ends.
#!/bin/ksh
ssh -t -X mylogin#myremotemachine 'cd $HOME/bin/folder1; echo $PWD; ssh -q -X ssh mylogin#myremotemachine; cd $HOME/bin/folder2; echo $PWD'
The PWD gets changed correctly before the second ssh. The reason for the second ssh is because it ends the script in the correct remote host but it will not retain the directory change which I attempted by putting commands after it but they won't execute.
Does anyone have any ideas?
Just launch a shell at the end of the command list:
ssh -t -X mylogin#myremotemachine 'cd $HOME/bin/folder1; echo $PWD; ssh -q -X ssh mylogin#myremotemachine; cd $HOME/bin/folder2; echo $PWD; ksh'
If you want the shell to be a login one (i.e. one that reads .profile), use exec -l:
ssh -t -X mylogin#myremotemachine 'cd $HOME/bin/folder1; exec -l ksh'
If the remote server uses an old ksh release that doesn't support the exec -l builtin and if bash or ksh93 is available, here is a workaround:
ssh -t -X mylogin#myremotemachine 'cd $HOME/bin/folder1; exec bash -c "exec -l ksh"'

How to execute a file in separate gnome terminal in linux

I want to execute a C program in separate terminal, I've tried this command,
gnome-terminal -x ./test
and
gnome-terminal -e test
But it opens a new terminal and before giving me output, it just vanish.
How could I solve this issue using gnome-terminal?
Thanks in advance
This might be what you search:
gnome-terminal -e "bash -c \"!!; exec bash\""
or (shortly):
gnome-terminal -x sh -c "!!; bash"
It opens gnome-terminal with your last command (!!) executed and it stays open with the command output in the shell, even with an interactive command like top or less...
In your case its:
gnome-terminal -e "bash -c \"./test; exec bash\""
or
gnome-terminal -x sh -c "./test; bash"

Resources