Yup. The FAQ (perlfaq8) says:
In the strictest sense, it can't be done -- the script executes as a different process from the shell it was started from. Changes to a process are not reflected in its parent, only in its own children created after the change. There is shell magic that may allow you to fake it by eval()ing the script's output in your shell; check out the comp.unix.questions FAQ for details.
"There is shell magic that may allow you to fake it"
is exactly what I'm after. At this point, I'm not worried about portability, compatibility or downright correctness. If it gets the job done, I'm game.
#!/home/bbq/bin/perl
# Trust no1!
| [reply] |
# ... stuff run every time this script is invoked
if [ "$checkvar" != "foo" ]; then
exec perl /usr/script/myscript.pl
else
# ... stuff to do after the script has run
fi
And in the perl script:
$ENV{checkvar}="foo";
exec "sh", "/usr/script/myshell.sh" # 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...
| [reply] [d/l] [select] |
ahunter++!
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/distinctuser.pl
logout
and my distinctuser.pl 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!
#!/home/bbq/bin/perl
# Trust no1!
| [reply] [d/l] [select] |