Re: Need /bin/sh script help

2006-04-12 Thread Garrett Cooper

Garrett Cooper wrote:


Hello again all,
   Just making a series of sh scripts to help automate updating and 
whatnot of my fileserver (since I am trying to avoid having mistakes 
occur with my system, and maybe help the community out a bit by 
providing some decent means of updating their own machines), and I was 
wondering if anyone could help me out with the following script I've 
developing (the grep if statements are incorrect..):


#!/bin/sh
#

KC=;

cd /usr/src;

if [ -n `grep -e s/KERNCONF=/ /etc/make.conf` ] # want to look for 
KERNCONF in /etc/make.conf

then
   echo enter in the kernel conf file full pathname:;
   read KERNCONF;
   KC=KERNCONF=$KERNCONF;
fi

if [ -n `grep -e s/NO_CLEAN=*yes*/ /etc/make.conf` ] // want to look 
for NO_CLEAN in /etc/make.conf -- is this really necessary?

then
   cd sys;
   echo cleaning sources
   make clean;
   make cleandir;
   cd ..;
fi

echo building kernel;
make buildkernel $KC;

echo installing kernel;
make installkernel $KC;

echo kernel compile complete. reboot to try new kernel;

TIA,
-Garrett

Thank you all for the replies and the advice. I still need to fix the 
grepping, but I hope that any and all problems will be resolved soon 
once I stick my mind to it. As for what worked and was changed, what 
didn't, and why I am doing this:


What worked/was changed:
-Removing C++ style comment. Lol.
-Adding in a loop for read so the kernconf variable is not set to null.

What didn't work:
-Using make -V (it came up with nothing... oddly enough even though the 
manpage said it would work).
-grep call when I didn't redirect stuff to stderr (suppose I should do 
that).


Why I am doing this:
If you're probably reading the mailing list from time to time, you'll 
have noticed I had some issues last week with cvsup and my system 
sources. I've basically come to the conclusion that the cause for my 
issue is the fact that I had a cron job which would update my 
system/kernel sources, as well as my ports, and my system/kernel sources 
were synced DURING a build, which lead to quite a few issues with the 
build and installworld, I discovered after rebooting the machine the 
next morning (no errors were encountered though, which was odd). So, in 
order to scratch the itch, persay, that exists with cvsup and building 
ports/compiling system stuff, I have created a script which does 'lock' 
a process, if noted correctly, with a 'semaphore lockfile'. Maybe a call 
to ps aux would be better, but I found that dealing with a lockfile 
system would be a much easier way to solve things.


Todo Plan:
Add an rc-script or something that will run in single-user mode which 
will help with mergemaster. People should be at the machine when doing 
this, and my scripts were originally designed so that a person could 
just run the script and it would do function X on a timed basis (say as 
a cron job).


These scripts aren't meant to replace any resources; they're just here 
to help automate junk and ensure that things DO get done properly and 
things DO get updated, with less typing and command memorizing for the 
admin (I will properly annotate which chapters in the handbook to use 
and manpages to read for a more in depth reference of what the script 
does and how it does it).


Furthermore, I plan on possibly coming out with a more up to date 
installcd setup that would have an 'admin pack' as I would call it, or 
apache, bind9, perl, mysql, ipfw, samba, etc, properly configured with a 
set of CGI pages that would help simplify system management for people 
(I am doing this as a project for the house/apt I'm living in since they 
need a NAT box with extras).


So, that's what I have in mind.

Questions, comments :) ?

-Garrett
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Need /bin/sh script help

2006-04-11 Thread RW
On Tuesday 11 April 2006 06:30, Garrett Cooper wrote:

 cd /usr/src;
 if [ -n `grep -e s/KERNCONF=/ /etc/make.conf` ] # want to look for
 KERNCONF in /etc/make.conf

if [ `make -V KERNCONF`  ]

 read KERNCONF;
 KC=KERNCONF=$KERNCONF;
 fi

You need to check that KC actually exists. IIRC a typo will cause GENERIC to 
build.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Need /bin/sh script help

2006-04-11 Thread Parv
in message [EMAIL PROTECTED],
wrote Garrett Cooper thusly...

 I was wondering if anyone could help me out with the following
 script I've developing (the grep if statements are incorrect..):
 
 #!/bin/sh
 #
 
 KC=;
 
 cd /usr/src;
 
 if [ -n `grep -e s/KERNCONF=/ /etc/make.conf` ] # want to look for 

Well, you did not write what exactly is the problem, as executing
the above works as expected.  Why do have 'KERNCONF' surrounded by
's/'  '/'?


In any case, there is not need to see if the returned string length
is nonzero.  Just use the grep return code  send the all the output
to /dev/null ...

  if grep -e '^KERNCONF=' /etc/make.conf /dev/null 21
  then
...
  fi


... or you could also use '-q' and/or '-s' grep options instead of
sending output to /dev/null.  (I personally would do a bit more
strict check to see $KERNCONF is set to value containing characters
meeting some criteria, say '\[-._[:alnum:]]+\'.)


 KERNCONF in /etc/make.conf
 then
echo enter in the kernel conf file full pathname:;

I did not know one can specify the kernel configuration path, not
just the basename.


read KERNCONF;
KC=KERNCONF=$KERNCONF;
 fi
 
 if [ -n `grep -e s/NO_CLEAN=*yes*/ /etc/make.conf` ] // want to look for 
   ^^
   ^^
Wrong kind of comment
character.

See above comments about grep(1) usage.


  - Parv

-- 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Need /bin/sh script help

2006-04-11 Thread [EMAIL PROTECTED]
On  Mon, 10 Apr 2006 22:30:32 -0700  Garrett Cooper wrote (my brief response 
follows all of his text):

Just making a series of sh scripts to help automate updating and 
whatnot of my fileserver (since I am trying to avoid having mistakes 
occur with my system, and maybe help the community out a bit by 
providing some decent means of updating their own machines), and I was 
wondering if anyone could help me out with the following script I've 
developing (the grep if statements are incorrect..):

#!/bin/sh
#

KC=;

cd /usr/src;

if [ -n `grep -e s/KERNCONF=/ /etc/make.conf` ] # want to look for 
KERNCONF in /etc/make.conf
then
echo enter in the kernel conf file full pathname:;
read KERNCONF;
KC=KERNCONF=$KERNCONF;
fi

if [ -n `grep -e s/NO_CLEAN=*yes*/ /etc/make.conf` ] // want to look for 
NO_CLEAN in /etc/make.conf -- is this really necessary?
then
cd sys;
echo cleaning sources
make clean;
make cleandir;
cd ..;
fi

echo building kernel;
make buildkernel $KC;

echo installing kernel;
make installkernel $KC;

echo kernel compile complete. reboot to try new kernel;

TIA,
-Garrett

I see a problem in the line
if [ -n `grep -e s/KERNCONF=/ /etc/make.conf` ] # want to look for 
you should have double-quotes around the  `grep  ...  conf`
because it is likely to produce more than one token and so the
 [ -n  ... ]  statement violates the syntax (there should be exactly 1 token 
between the  -n  and the  ] , even no token there is an error, the way that is 
handled is to quote it.
I am writing this quickly without bringing up my  FreeBSD  system to check it.  
Good luck.

Another thing you can do to avoid quoting (and the long strings that may 
result) is use the  -c  option of  grep  and check the number resulting.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Need /bin/sh script help

2006-04-11 Thread Jan Grant
On Tue, 11 Apr 2006, [EMAIL PROTECTED] wrote:

 On  Mon, 10 Apr 2006 22:30:32 -0700  Garrett Cooper wrote (my brief response 
 follows all of his text):
 
 Just making a series of sh scripts to help automate updating and 
 whatnot of my fileserver (since I am trying to avoid having mistakes 
 occur with my system, and maybe help the community out a bit by 
 providing some decent means of updating their own machines), and I was 
 wondering if anyone could help me out with the following script I've 
 developing (the grep if statements are incorrect..):

 I see a problem in the line
 if [ -n `grep -e s/KERNCONF=/ /etc/make.conf` ] # want to look for 
 you should have double-quotes around the  `grep  ...  conf`
 because it is likely to produce more than one token and so the
  [ -n ... ] statement violates the syntax (there should be exactly 1 
 token between the -n and the ] , even no token there is an error, the 
 way that is handled is to quote it. I am writing this quickly without 
 bringing up my FreeBSD system to check it.  Good luck.

Or simply use the error status of grep, no [ invocation:

if grep -q ...
then
...
fi

Note that if you're looking at automating the update process you should 
probably pay careful attention to the world/kernel update process 
described in the handbook; there are steps (like an initial mergemaster 
-p) that you will want to include.

-- 
jan grant, ISYS, University of Bristol. http://www.bris.ac.uk/
Tel +44 (0)117 3317661   http://ioctl.org/jan/
If you have received this email in error, do whatever the hell
you want with it. It's not like I can stop you anyway.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]