Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

RE: RE: RE: chdir vs. shell behavior

by ahunter (Monk)
on Jun 15, 2000 at 01:52 UTC ( #18199=note: print w/replies, xml ) Need Help??

in reply to RE: RE: chdir vs. shell behavior
in thread chdir vs. shell behavior

On the one occasion I had cause to do this, I exec'd the perl script from the login script, and exec'd a new shell from the perl script. Problem was, that launched the shell twice - easily solved in my case, as I had the luxury of making the perl script the login shell for the relevant users. This also solves the problem of needing to stop the script from executing twice (either by assuming a login shell the first time around, or setting an environment variable from within the script)

As someone else pointed out, passing the output from the script to a cd command works too. But things complicate if you want to change more of the environment than just the directory...

That is (shell script):

# ... stuff run every time this script is invoked if [ "$checkvar" != "foo" ]; then exec perl /usr/script/ else # ... stuff to do after the script has run fi
And in the perl script:
$ENV{checkvar}="foo"; exec "sh", "/usr/script/" # or, if you're logging in exec "sh", "-l"
There may be a problem if the shell script is not being executed as part of a login sequence, as you can't assume the environment is trustworthy. I suspect in most cases all someone who fakes the variable is going to do is make the perl script fail to run...

Replies are listed 'Best First'.
RE: RE: RE: RE: chdir vs. shell behavior
by BBQ (Deacon) on Jun 15, 2000 at 16:36 UTC

    Right before I read your post, I tried something that was almost there and gave me some p-r-e-t-t-y stupid results. The following is an example of what NOT TO DO:
    .bashrc contained: # last line exec /usr/global/ logout
    and my user:
    # check for files, connect via DBI, make toast, etc... chdir('/bar'); system('/bin/bash'); exit;
    So, now that I had everything setup, I logged in. BOOM!!! At the end of .bashrc, we get perl, and the end of perl we call bash (and .bashrc again), and over and over. I just stood there looking at the screen wondering for a second or two why I was getting 800 printouts of fortune.

    The method you just described works perfectly. Its true tho that there will be 2 bashes and 1 perl running per user, but that doesn't seem to be affecting the system load. It isn't a heavily used machine anyway. Thanks!

    # Trust no1!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://18199]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2018-03-20 15:35 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (254 votes). Check out past polls.