LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2003, 06:37 AM   #1
t3kn0lu5t
LQ Newbie
 
Registered: Aug 2003
Location: Indiana
Distribution: Debian recently from FreeBSD
Posts: 28

Rep: Reputation: 15
I'm stumped - Script question


Yes, I am a linux newbie, but I'm not stupid. First time using linux and I've managed to find comfort in Gentoo. Alas, I'm stuck on something simple, I just can't find the resource to solve my problem.

I've created a little script to setup my network for my work environment. It's called worknet.sh. I keep it in my home dir, and I run it as root so I can do emerge from work. the contents follow:

dhcpcd eth0
export http_proxy="hteeteep://ipaddress.that.it.won't.let.me.postort"
export ftp_proxy="fteep://ipaddress:21"

(the IPs have been changed.)
My problem is that dhcpcd runs fine, and sets up eth0, but my exports never take cause I end up having to type them in manually after I run the script in order for emerge to find the proxy.
What am I doing wrong?

Thanks in advance
 
Old 09-25-2003, 08:47 AM   #2
cadj
Member
 
Registered: Aug 2003
Location: Melbourne Australia
Distribution: LinuxMint Elyssa
Posts: 374

Rep: Reputation: 32
have u checked the case?

export DISPLAY=192.168.0.1:0.0

and mayb u dont need the "" marks

not sure but try it
 
Old 09-25-2003, 12:53 PM   #3
t3kn0lu5t
LQ Newbie
 
Registered: Aug 2003
Location: Indiana
Distribution: Debian recently from FreeBSD
Posts: 28

Original Poster
Rep: Reputation: 15
I don't think that would matter because when I use the export command at the prompt I use all lower case and it works. It's the exact same way in the script.
 
Old 09-25-2003, 01:02 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Well, not wrong, but for Bash global exports are usually done from /etc/profile, /etc/bashrc and the stuff in /etc/profile.d depending on it being a login or non-interactive shell. If you don't want to have it exported globally, then you'd have to remember those exports will only live as long as you run that script. here's an outline of how things get sourced by default:
Code:
Bash invoked as "/bin/bash"
interactive login shell:
/etc/profile
        + /etc/inputrc
        + /etc/profile.d/*.sh
~/.bash_profile
        + ~/.bashrc
                + /etc/bashrc
        + ~/.bash_login
        + ~/.inputrc
~/.bash_login

interactive non-login shell or non-interactive:
        + ~/.bashrc
                + /etc/bashrc
                        + /etc/profile.d/*.sh

Bash invoked as "/bin/sh"
interactive login shell or non-interactive shell (with --login)
/etc/profile
~/.profile
If "emerge" doesn't require arguments, just tack it onto the script at the end, if "emerge" does, then you can supply them on the commandline:


#!/bin/sh
# Check if the interface is up already
/sbin/ifconfig eth0 2>/dev/null|tr -s " "|grep -qe "^ UP";
case "$?" in 0) ;; *) dhcpcd eth0;; esac
# Minimal check if exported values are available
case "${#http_proxy}" in
0) export http_proxy="hteeteep://ipaddress.that.it.won't.let.me.postort";; esac
case "${#ftp_proxy}" in
0) export ftp_proxy="fteep://ipaddress:21";; esac

case "$@" in
0) echo "Running emerge with no options"; emerge;;
*) case "$1" in
h|-h|--help) echo "$(basename $0) <emerge options>"; exit 1;;
*) echo "Running emerge with options \"$@\""; emerge "$@";;
esac;;
esac
 
Old 09-25-2003, 02:22 PM   #5
Medievalist
Member
 
Registered: Aug 2003
Distribution: Dead Rat
Posts: 178

Rep: Reputation: 38
Listen to unSpawn.

Basically, exports are only inherited by child processes, and cannot be "pushed back up the process tree".

Your shell script sets some variables, they are available in that script only. You export them, and they are available in processes initiated by that script. But regardless of what you do, once that script exits the variables go away.

When you type them in, you're setting them in the current environment space, rather than in a script's private space.
This is a fundamental design feature of *nix. It's called "inheritance" because it only goes one way...

Maybe what you want to do is call dhcpcd at boot time, then set your variables at login time. Or do both at login time from .profile or .bashrc .
 
Old 09-25-2003, 08:16 PM   #6
t3kn0lu5t
LQ Newbie
 
Registered: Aug 2003
Location: Indiana
Distribution: Debian recently from FreeBSD
Posts: 28

Original Poster
Rep: Reputation: 15
I see.. Thanks for explaining inheritance to me, and thanks for the example script!
 
Old 09-26-2003, 02:26 AM   #7
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 42.1_64+Tumbleweed-KDE, Mint 17.3
Posts: 3,951

Rep: Reputation: Disabled
Thumbs up

Neat piece, unSpawn . That's a lot explained.
Thanks also, Medievalist.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Firewall question - stumped by 1 rule! thekillerbean Linux - Networking 4 08-27-2005 02:59 AM
I've finally been stumped. glorb Linux - Newbie 12 07-01-2004 06:58 AM
how to im stumped rocketgo Linux - Software 8 11-10-2003 11:10 PM
really has me stumped! brunogartner Linux - Newbie 4 06-30-2003 06:43 AM
Stumped with IPTABLES TruckStuff Linux - Security 6 06-16-2002 08:54 AM


All times are GMT -5. The time now is 04:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration