2

I am using Ubuntu 16.04.2, I have an icon on my desktop that links to a script in my $HOME/bin directory. This script uses two scripts in the $HOME/bin directory. It opens a terminal and prints the output script one. Then it opens a second terminal and prints the output of script two.

I would like it to print all the data to just one terminal. The end product should be that when I click my desktop icon all the data will be printed to just one terminal.

Many thanks for your suggestions

#!/bin/bash
gnome-terminal -e "bash -c $HOME/bin/bin_old/bk_up;bash" && gnome-terminal -e "bash -c $HOME/bin/bin_old/win_bkp;bash"
George Udosen
  • 36,677

2 Answers2

4

Instead of opening a second gnome-terminal just execute the two commands in the first one.

#!/bin/bash
gnome-terminal -e "bash -c $HOME/bin/bin_old/bk_up;$HOME/bin/bin_old/win_bkp;bash"

EDIT

From what has been discussed in the comments what Richard wants is something like this:

#!/bin/bash
$HOME/bin/bin_old/bk_up
if [ $? -eq 0 ]; then
    $HOME/bin/bin_old/win_bkp
fi

Basically it runs the first script and if runs successfully (without returning errors) it runs the second script.

Ricardo Rodrigues
  • 866
  • 1
  • 9
  • 22
  • Entirely the point of my question Ricardo: How do I get both scripts to print their data to one terminal. – Richard Hill Mar 10 '17 at 00:25
  • when you call gnome-terminal you are creating a new instance of a terminal, meaning that calling it 2 times will open a terminal window. The solution I provide does what you describe: open a terminal; Run both scripts; scripts print their data to the terminal. – Ricardo Rodrigues Mar 10 '17 at 13:55
  • Wait, do you want the scripts to run in parallel? Where you would open two terminals running the scripts and have one of them also printing the other's output? – Ricardo Rodrigues Mar 10 '17 at 13:57
  • Your answer does print to one screen. However, you changed my script. I need to use && not ; . When I use && the screen disappears and I see no results. This was the reason behind submitting this post. – Richard Hill Mar 10 '17 at 17:24
  • Then please provide more information to the question. Do the scripts continue to run or are they just a quick run type (like ls ~)? What do the scripts do? – Ricardo Rodrigues Mar 10 '17 at 18:10
  • The first script backs up my system to a directory and prints out the backup details. Only if this was successful, then the second script backs up that directory to a remote system prints out the details and shuts down my current system. Thanks for any help you can give Ricardo. – Richard Hill Mar 11 '17 at 23:53
0

With considerable help from Ricardo Rodrigues. Here is the solution that best suits what I am trying to achieve. If the first piece of code is successful then the second piece of code will execute. If it is not successful then a terminal window will open telling me where to find details of the errors. If the second piece of code is successful then I will know for sure that my system has been backed up locally and also backed up to a remote system and then shutdown locally. However if there are errors it will open a terminal window and tell me where to find details of the errors. As you can see I have given up trying to have everything display in a single pop-up terminal window. This seems to keep it simple for me. Now when I click my desktop icon either the system will backup to a local and remote system, and then shut down, or I will receive an error message in a pop-up terminal.

#!/bin/bash
if bk_up 2> $HOME/local_errors     # backup to local directory
then
    if win_bkp 2> $HOME/remote_errors  # backup to remote system
    then
        shutdown now
        exit
    else
        echo "echo Remote errors. Check remote_errors file" > $HOME/warn2
        chmod ugo+x $HOME/warn2 # needs to be executable for gnome-termial to work.
        gnome-terminal -e "bash -c $HOME/warn2;bash"
        exit
    fi
else
   echo "echo Local errors. Check local_errors file" > $HOME/warn1
   chmod ugo+x $HOME/warn1  # need to be executable for gnome-terminal to work.
   gnome-terminal -e "bash -c $HOME/warn1;bash"
   exit
   exit
fi