Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Bash global variable?

    Hello forum,

    I am new to bash scripting, and have encountered a small problem..
    The story goes like this,

    I want to create a mail-tunnel from my home pc so that I can access my work email, so i thought I can put it as an eval command in my .bash_profile , and then set some environment variable that checks if the mail tunnel is active, and if not execute the tunnel command, else just ignore...

    The part of my .bash_profile doing this looks like this :
    #---Setting the mail_tunnel only ONCE !
    if [ $TUNNEL!="TRUE" ]; then
    ssh -L 2525:localhost:25 -N **.** &
    export TUNNEL=TRUE
    now you can see that this will work only inside the bash profile, i.e. if I create a new terminal, then $TUNNEL does not exist, and the ssh will be evaluated again... so i will end up with no of tunnels = no of terminals ,
    something that i don't want...

    So i am wondering wondering, is there a way of setting TUNNEL in a Global scope (i.e. for all terminals etc) ,
    or any smarter way of doing this?

    Your help is greatly appreciated,

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    St. Petersburg, FL
    You could place TUNNEL's value in a file (e.g. /home/foo/tunnel.txt), and read the value from there:
    . /home/foo/tunnel.txt
    if [$TUNNEL!="TRUE"]
    Or something like that.

  3. #3
    Thanks for that,
    I'll have a go...

  4. $spacer_open
  5. #4
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Seattle, WA, USA
    You might also consider making this an init script, so that the tunnel would set up when you boot Linux, and you don't have to worry about it later. The exact process differs based on distro, but you should be able to find some resources about.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts