0

I have the following bash script in Linux Ubuntu which opens a new terminal with multiple tabs and in each tab it executes ssh command to access a remote router:

#!/bin/bash

gnome-terminal --tab -e "ssh root@172.16.17.4" --tab -e "ssh root@172.16.17.5"

In the bashrc file, I have included the definition of the following alias commands:

alias router4='ssh root@172.16.17.4'
alias router5='ssh root@172.16.17.5'

When I replace the full ssh command in the first script with these alias commands, each Tab gives me the following error:

There was an error creating the child process for this terminal

Failed to execute child process "router6" (No such file or directory)

How to solve this problem?

Note: When I execute the previous alias commands in a maually opened tab, they work perfectly.

Community
  • 1
  • 1

2 Answers2

0

You need to execute it through bash:

gnome-terminal --tab -e "bash -c router4"
xlm
  • 6,854
  • 14
  • 53
  • 55
odradek
  • 993
  • 7
  • 14
  • The terminal launches but the it reports `bash: router4: command not found`. I also added `shopt -s expand_aliases` but nothing changed. –  Apr 25 '17 at 18:47
  • well, yes, you didn't specify that in your question; to keep the window open check these solutions: http://stackoverflow.com/a/3512861/5348860 – odradek Apr 25 '17 at 18:55
  • I solved the issue of keeping the terminal open, it is done by changing profile name. Now i have another problem, please check my previous answer. –  Apr 25 '17 at 18:59
  • is everything in this workflow being done as the same user? – odradek Apr 25 '17 at 19:08
0

You could try switching from an alias to a function in your .bashrc. According to bash's documentation, functions are better than aliases for most situations. In your situation, since you're not running bash as a login environment, it might work better. Add this to your .bashrc and comment out the alias:

router4() {
    /usr/bin/ssh root@172.16.17.4
}

If that doesn't work on its own, you could try adding export -f router4 in your .bashrc after defining router4.

dogoncouch
  • 251
  • 3
  • 9