Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write a function in bash_profile

how can we write a simple regular function which i can put in my bashprofile which can be used to secure console to any host i want.

but my secure console has to go through a jump host. that is the issue.

function func_name () {
 ssh jumphostname; 
 sc $hostname # from jump host secure console to another host given as input from terminal
}

this function only making to login in to jump host but not to secureconsole in to another host from there.

-bash-4.1$func_name host.me.com should give me console to host.me.com via jumphost

is function for this not possible? do i have to write a script?

like image 853
stackuser Avatar asked Sep 09 '26 15:09

stackuser


1 Answers

Here's how I do it.

  1. Create a functions folder at home
  2. Write my function as a shell script
  3. Reference the file as an alias in my bash_profile
  4. Reset the source

Example

mkdir ~/.functions
echo '#!/bin/bash
      echo $1' > ~/.functions/ekho
echo 'alias ekho="sh ~/.functions/ekho"' >> ~/.bash_profile
source ~/.bash_profile

Now you can call your method from any location for ever ever.

ekho "Wow"
like image 107
Proximo Avatar answered Sep 12 '26 23:09

Proximo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!