OK, so presumably you are using JAIL_1 (in this example) as a persistent variable across different scripts, so script1 could set it, script2 use it and then script3 change it.
You are right in that csh is the only shell which will allow you to modify the parent's environment. What's usually done here is to write the data into a source-able script, ie:
t1.sh
Code:
#!/bin/sh
echo "JAIL_1=/mnt/e/Database1" > ./sh-vars.txt
t2.sh
Code:
#!/bin/sh
if [ -f ./sh-vars.txt ]; then
. ./sh-vars.txt
echo "JAIL_1 is $JAIL_1"
else
echo "sh-vars.txt expected, not found"
fi
t3.sh
result:
Code:
$ ./t1.sh
$ ./t2.sh
JAIL_1 is /mnt/e/Database1
$ ./t3.sh
$ ./t2.sh
sh-vars.txt expected, not found
The script below started my serious use of
csh. Because it seems that when dealing with environment variables for jails built from scratch in the way I done exposed more truth. So presumably what we just notice about
csh, I think the early developers of FreeBSD knew that
! and possibly other special characters usages would lead to danger for inexperienced users. They knew if a user uses one in a typo it could blow a system fuse, depending. I been there I think,
I blew a few MBR’s or fuses, now I kind of see why. The only one that gave me a real clue was when I notice my ntfs partitions were gone. No matter how I tried to recover them I end up having to resort to my backup drive a day latter. Of course this could have been something else I done wrong. Anyway, I think they figure why not simply discourage usages, which only makes good sense it is the most important shell of the base system.
This is pure speculation but it makes sense and now
I/we know how NOT to use it, if one ever do use it. If the kernel silently tells me
sh don’t work, I’m going to try
csh since I know it can be the solution sometimes.
A work around just to use
sh could cause other problems down the road, but I’ll play with it just to see. However, I make no promise to give up what has been working perfectly before my eyes everyday no matter how hard I pound and play with it for nearly a year. I rip and tear down jails just to test the backup-tar for months at a time because I made changes daily and needed to keep up with them. I had nothing better to do while trying to learn webbing.
I usually do things by the handbook first, and then I read blogs for weeks that may point out what the handbook might be missing, but with respect for the handbook, where else could they/we have start. I like how-to and if it don’t work for whatever simple reason I usually find other ways that may not be so common. I use section-6 blogs and a few others where I had to mix and match, then modify a few things make it work. So don’t let what I done throw you off. I’m moving to vImages jails and when I’m done it will never fail (thanks to 11). Doing things the hard way makes you pay attention to every detail 100 times over, but it cost you major time.
leebrown66, your scripts are going to be my road map to
real scripting. Once I see a relation to what I have interest in it makes understanding how things work much more clearer when nothing else did. I think it been the fear of going in too deep for me. I had other plans.
Anyway, in the past I made many changes to this file to make it work differently for something else but it should give you the complete idea of where those other scripts above came from and why I use accidently used
csh for something else which brought me to posting the question. If someone uses it, step through it a few pieces at a time to catch any possible flaw do to any of my previous changes. If I remember correctly, it still 100% flawless. Try session-6, then you know why I came up with what I have. It even proves newer versions of FreeBSD causes minor changes. Still section6 been in like Flint with the best of the rest!
http://tutorials.section6.net/home
Database_1 is the name of the jail
JAIL_1 is the environment like
$DESTDIR
For full
effect - uncomment some of what is within the file.
A_InstallWorld - use this to re-install or make a new jail.
b_delete.jail - must delete old jail to re-install or use the backup tar.
c_untar.jail - using backup tar to replace jail, but leave slop, delete it first?
d_start - start the jail.
e_kill-environment - must kill env before closing the jail console.
tar-it - if you including new stuff, back it up with this... Will delete old tar first!
view-env - view your jail environment, see what is in that shell.
csh is cool here!
Code:
#!/bin/csh
# @@@@@@@@@@@@@@@@@@@@@@@@@@ Database1 InstallWorld
# @@@@@@@@@@@@@@@@@@@@@@@@@@ DELETE Database1 first
# .................................. Build RESORT ... first 2 lines you can change
# .................................. Build RESORT ... to make a new complete RESORT
# @@@@@@@@@@@@@@@@@@@@@@@@@@ DELETE Database1
# ..... >
#cd /mnt/e/
#chflags -R noschg /mnt/e/Database1/*
#sleep 3
#rm -Prf /mnt/e/Database1
#sleep 3
# ..... >
#cd /mnt/j/MAKE/
#rm -Pr Database1.tgz
#sleep 3
#
#
#mkdir /mnt/j/MAKE/Database1
#echo "--is error?--"
#echo "-----"
#echo "-----"
echo "Now deleting old. We will InstallWorld in 4 minutes..."
#cd /mnt/j/MAKE/Database1
#chflags -R noschg *
#rm -Prf *
#rm Pf .cshrc
#rm Pf .profile no no#
#cd ..
# Never delete the first directory even if hand made.
# @@@@@@@@@@@@@@@@@@@@@@@@@@ InstallWorld
#sleep 2
#mkdir /mnt/j/MAKE/Database1
cd /mnt/e/
setenv JAIL_1 /mnt/e/Database1
# cp /etc/mnt/j/MAKE.conf /etc/mnt/j/MAKE.conf
mkdir -p $JAIL_1/dev
mkdir -p $JAIL_1/etc
mkdir -p $JAIL_1/usr/ports
mkdir -p $JAIL_1/usr/src
mkdir -p $JAIL_1/usr/tmp
chmod 777 $JAIL_1/usr/tmp
cd /usr/src/
# make buildworld
#make installworld DESTDIR=$JAIL_1
make installworld DESTDIR=$JAIL_1 SRCCONF=/etc/src.conf
# @@@@@@@@@@@@@@@@@@@@@@@@@@ mergemaster
sleep 2
mergemaster -a -C -D ${JAIL_1}
#mergemaster -i ${JAIL_1}
sleep 2
cd /usr/src/etc
cp /etc/resolv.conf $JAIL_1/etc
cp /etc/mnt/j/MAKE.conf $JAIL_1/etc
# @@@@@@@@@@@@@@@@@@@@@@@@@@ distribution
sleep 2
make distribution DESTDIR=$JAIL_1 OPTIONS_UNSET=OPENSSH OPTIONS_UNSET=OPENSSL
sleep 2
rm -Pf $JAIL_1/etc/ssl/openssl.cnf
mkdir -p $JAIL_1/usr/local/openssl
cp /etc/ssl/openssl.cnf $JAIL_1/etc/ssl
cd $JAIL_1/usr/local/openssl/
sleep 2
ln -s ../../../etc/ssl/openssl.cnf openssl.cnf
# ...............................
# ...............................
# ...............................
# ...............................
# @@@@@@@@@@@@@@@@@@@@@@@@@@ devfs
mount -t devfs devfs $JAIL_1/dev
devfs -m $JAIL_1/dev rule -s 4 applyset
sleep 2
cd $JAIL_1
ln -s dev/null kernel
touch $JAIL_1/etc/fstab
# @@@@@@@@@@@@@@@@@@@@@@@@@@ CLEANUP - TURN-OFF ENV
sleep 2
umount -A -t devfs
unsetenv JAIL_1
sleep 2
# @@@@@@@@@@@@@@@@@@@@@@@@@@ MAKE BACKUP tar afar
#cd /mnt/j/MAKE/
#rm -Pr Database1.tgz
#sleep 1
#cd /mnt/e
#tar cvzf /mnt/j/MAKE/Database1.tgz Database1/
# @@@@@@@@@@@@@@@@@@@@@@@@@@ delete temproot
#sleep 2
#cd /var/tmp/temproot
#chflags -R noschg *
#rm -Prf *
#rm P .cshrc
#rm P .profile
#cd ..
#rm -Prf temproot
#sleep 2
#exit
echo "-----";
echo "-- done ........................."
sleep 1000
No better than the rest, but no less than the best
