Help need wth shell script

Help need wth shell script

Post by Sean Woodlo » Mon, 11 Nov 2002 08:06:09



Hi
Let me start me explaining what i am try to acheive.  Ok here the
deal, i am try to restrict samba users so that they can only see local
site  specfic printers when they log into our samba servers.  Because
our network in completely Unix based ie solaris 8/9 , all our printers
are setup to use nis maps.  The problem we have is that all printers
in the domain become viewable and  avaliable to users anyway.

So i need to write a srcipt that grep the netbios name as a string,
strip away unwanted characters to leave me with a buliding code.

This is then assigned in a variable and is used as the search
creteria. This seems to be ok, but we still have some printers that
have the old naming convention, which are not consistently named.

So i thought maybe if i collect all the ones with the old printers
names for each site and put them in a file called nospecfic and then
append them to the end of /etc/printers.conf.

This script will be run from the cron job once day so that if any new
printers are added the local printers.conf will be appended.

I am really looking for some advice on what you think in principle,
and maybe some advice on how to proceed. I am hoping for a generic
script that can run on all the servers without having to make
individual changes to each server

As you can tell i am new to this, i am a student and could really use
some good advice.

here the script so far..

#/bin/sh -x
#Printer.sh
#created by  Me
#date:21/10/2002
#searches for printers by building code
BUILDING=`grep -i 'netbios name' /opt/samba/lib/smb.conf | awk -F- '{
print $2}' | sed 's/^.//;s/[0-9]\{2\}//'`

if [ -n "$BUILDING" ] ; then
        [ -f /etc/printers.conf ] && cp -p /etc/printers.conf
/var/tmp/printers.conf.`date +%d%m%Y`
        ypcat printers.conf.byname | grep -i $BUILDING >
/etc/printers.conf
else
        echo "`hostname`: Unable to find building code" | mailx

        exit 1
fi

grep -i solaris /opt/samba/lib/nospecfic  >> /etc/printers.conf

/etc/init.d/samba stop
/etc/init.d/samba start

if ps -ef | grep -v grep | grep smbd >/dev/null 2>&1 ; then
        echo  "`uname -n`: Samba printers.conf was successfully

om
else
        (
        echo "ps listing:"
        ps -ef | egrep "smbd|nmbd"
        echo
        echo "smb log:"
        tail -20 `ls -t /var/log/samba/*.smb | head -1`
        echo
        echo "nmb log:"
        tail -20 `ls -t /var/log/samba/*.nmb | head -1`

fi
exit 0

here is a sample of the output from a ypcat.printers.conf.byname|grep
-i $BUILDING CODE,.

mikeex2lgo:bsdaddr=mid-nw,mikeex2lgo,Solaris:
pmar04007sgl|pmar04007|city:bsdaddr=city,pmar04007sgl,Solaris:
:descriptio
n={X.X.X.X/X}mar04 tray1: :location=Headoffice:
san-xerox-m|san-xerox-msgl:description={+X.X.X/X}SAN01 manchester
office
: :location=SAN01 manchester office:
:bsdaddr=sand-nw,san-xerox-m,Solaris:
pmar04011tr2:bsdaddr=city-wts,pmar04011tr2,Solaris:
:description={X.X.X/X
8}mar04 tray2: :location=mar04,1st Floor:
pdar03217sgl:bsdaddr=prdar-print1,pdarp03217sgl,Solaris:
pdar02020|pdar02020sgl:bsdaddr=prdar-print1,pdar02020sgl,Solaris:
pdar01234tr2:bsdaddr=prdar-print1,pdar01234tr2,Solaris:
pdar01060|pdar01060sgl:bsdaddr=prdar-print1,pdar01060sgl,Solaris:
pdar01020sgl:bsdaddr=prdar-print1,pdar01020sgl,Solaris:
de-xerox-m|de-xerox-b|de01007tr2|007-msgl:bsdaddr=ent
,Solaris: :description=Queue for de01007 Manual Feeder Tray (A4 fi
xed):
pmar04005tr2b:bsdaddr=city,pmar04005tr2,Solaris: :description={X
.X.X/X}mar04 tray2: :location=mar04,2nd Floor:
pdar03008sgl:bsdaddr=prdar-print1,pdar03008sgl,Solaris:
pdar01256sgl:bsdaddr=prdar-print1,pdar01256sgl,Solaris:
pdar01234|pdar01234dbl:bsdaddr=prdar-print1,pdar01234dbl,Solaris:
san-copiersgl|san-copier:description={+X.X.X/X}SAN01 :
:location=SAN01: :bsdaddr=san,san-copier,Solaris:
pmar07007sgl|pmar07007:bsdaddr=mar07-01,pmar07007sgl,Solaris:
:description={
X.X.X/X}mar07 tray1: :location=mar07,2nd Floor:
latsgl:bsdaddr=pr-bst04-01,latsgl,Solaris:
02053sgl: :bsdaddr=prmar-print1,pmar02053sgl,Solaris:
cont2|cont2tr2|contpe2sgl:bsdaddr=ned,Solaris:

Any  hostname that does start with a 'p' or a 'e' isn't using the
current standard naming convention.

This is just a sample.  All netbios names follow this fomat
"hostname-p|e$XXX02"
where XXX=buliding code.

Like i said im just looking of some advise on what you the best way to
proceed.

Many
Thanx

 
 
 

Help need wth shell script

Post by Sean Woodlo » Tue, 12 Nov 2002 02:27:26



> Hi
> Let me start me explaining what i am try to acheive.  Ok here the
> deal, i am try to restrict samba users so that they can only see local
> site  specfic printers when they log into our samba servers.  Because
> our network in completely Unix based ie solaris 8/9 , all our printers
> are setup to use nis maps.  The problem we have is that all printers
> in the domain become viewable and  avaliable to users anyway.

> So i need to write a srcipt that grep the netbios name as a string,
> strip away unwanted characters to leave me with a buliding code.

> This is then assigned in a variable and is used as the search
> creteria. This seems to be ok, but we still have some printers that
> have the old naming convention, which are not consistently named.

> So i thought maybe if i collect all the ones with the old printers
> names for each site and put them in a file called nospecfic and then
> append them to the end of /etc/printers.conf.

> This script will be run from the cron job once day so that if any new
> printers are added the local printers.conf will be appended.

> I am really looking for some advice on what you think in principle,
> and maybe some advice on how to proceed. I am hoping for a generic
> script that can run on all the servers without having to make
> individual changes to each server

> As you can tell i am new to this, i am a student and could really use
> some good advice.

> here the script so far..

> #/bin/sh -x
> #Printer.sh
> #created by  Me
> #date:21/10/2002
> #searches for printers by building code
> BUILDING=`grep -i 'netbios name' /opt/samba/lib/smb.conf | awk -F- '{
> print $2}' | sed 's/^.//;s/[0-9]\{2\}//'`

> if [ -n "$BUILDING" ] ; then
>         [ -f /etc/printers.conf ] && cp -p /etc/printers.conf
> /var/tmp/printers.conf.`date +%d%m%Y`
>         ypcat printers.conf.byname | grep -i $BUILDING >
> /etc/printers.conf
> else
>         echo "`hostname`: Unable to find building code" | mailx

>         exit 1
> fi

> grep -i solaris /opt/samba/lib/nospecfic  >> /etc/printers.conf

> /etc/init.d/samba stop
> /etc/init.d/samba start

> if ps -ef | grep -v grep | grep smbd >/dev/null 2>&1 ; then
>         echo  "`uname -n`: Samba printers.conf was successfully

> om
> else
>         (
>         echo "ps listing:"
>         ps -ef | egrep "smbd|nmbd"
>         echo
>         echo "smb log:"
>         tail -20 `ls -t /var/log/samba/*.smb | head -1`
>         echo
>         echo "nmb log:"
>         tail -20 `ls -t /var/log/samba/*.nmb | head -1`

> fi
> exit 0

> here is a sample of the output from a ypcat.printers.conf.byname|grep
> -i $BUILDING CODE,.

> mikeex2lgo:bsdaddr=mid-nw,mikeex2lgo,Solaris:
> pmar04007sgl|pmar04007|city:bsdaddr=city,pmar04007sgl,Solaris:
> :descriptio
> n={X.X.X.X/X}mar04 tray1: :location=Headoffice:
> san-xerox-m|san-xerox-msgl:description={+X.X.X/X}SAN01 manchester
> office
> : :location=SAN01 manchester office:
> :bsdaddr=sand-nw,san-xerox-m,Solaris:
>  pmar04011tr2:bsdaddr=city-wts,pmar04011tr2,Solaris:
> :description={X.X.X/X
> 8}mar04 tray2: :location=mar04,1st Floor:
> pdar03217sgl:bsdaddr=prdar-print1,pdarp03217sgl,Solaris:
> pdar02020|pdar02020sgl:bsdaddr=prdar-print1,pdar02020sgl,Solaris:
> pdar01234tr2:bsdaddr=prdar-print1,pdar01234tr2,Solaris:
> pdar01060|pdar01060sgl:bsdaddr=prdar-print1,pdar01060sgl,Solaris:
> pdar01020sgl:bsdaddr=prdar-print1,pdar01020sgl,Solaris:
> de-xerox-m|de-xerox-b|de01007tr2|007-msgl:bsdaddr=ent
> ,Solaris: :description=Queue for de01007 Manual Feeder Tray (A4 fi
> xed):
> pmar04005tr2b:bsdaddr=city,pmar04005tr2,Solaris: :description={X
> .X.X/X}mar04 tray2: :location=mar04,2nd Floor:
> pdar03008sgl:bsdaddr=prdar-print1,pdar03008sgl,Solaris:
> pdar01256sgl:bsdaddr=prdar-print1,pdar01256sgl,Solaris:
> pdar01234|pdar01234dbl:bsdaddr=prdar-print1,pdar01234dbl,Solaris:
> san-copiersgl|san-copier:description={+X.X.X/X}SAN01 :
> :location=SAN01: :bsdaddr=san,san-copier,Solaris:
>  pmar07007sgl|pmar07007:bsdaddr=mar07-01,pmar07007sgl,Solaris:
> :description={
> X.X.X/X}mar07 tray1: :location=mar07,2nd Floor:
> latsgl:bsdaddr=pr-bst04-01,latsgl,Solaris:
> 02053sgl: :bsdaddr=prmar-print1,pmar02053sgl,Solaris:
> cont2|cont2tr2|contpe2sgl:bsdaddr=ned,Solaris:

> Any  hostname that does start with a 'p' or a 'e' isn't using the
> current standard naming convention.

> This is just a sample.  All netbios names follow this fomat
> "hostname-p|e$XXX02"
> where XXX=buliding code.

> Like i said im just looking of some advise on what you the best way to
> proceed.

> Many
> Thanx

Ok excuse the typo, lack of sleep and too much beer.  Anyway earlier
I said that

Quote:> here is a sample of the output from a ypcat.printers.conf.byname|grep
> -i $BUILDING CODE,.

What I meant to say was that was just an output from a
ypcat.printers.conf.byname.  When I grep for building code I get
nearly all specified printers that I require that use the proper
naming convention however it does often pick up a few stray printers
from other sites.

I think i will need to use a tighter search pattern in order for it to
work consistently.

Thanks Again

 
 
 

1. Shell Script Help (C-Shell Script)

In my class we had to write a C program and now we have to write a shell
script to do the exact same thing. I am not sure where to get started using
tr and sed to accomplish this assignment. Here is the assignmnet...

--------------------------------------------------------------
(1) remove all non-printing characters (character codes 1 through 31,
   and 127) and replace them with the same sort of codes the vi
   editor uses.  For example, the bell character (character code 7)
   is replaced by the two printable characters "^" and "G" (G is the seventh
   letter of the alphabet).  Appendix I of Foster lists the ASCII character
   set, and it shows all the proper two-character sequences that should
   be used for the non-printing characters.  There are two special cases:
   Replace the delete character by "^?".  Newlines should be replaced by a
   dollar sign ("$") and then an actual newline.
   **you may ignore NUL (character code 0)**

(2) delete all non-ASCII characters (those with character codes 128 through
255).

(3) truncate all output lines that would otherwise extend past column 72.
Begin
   reading the data on the next line after ignoring the rest of the
character past column 72.

Make sure it reads from stdin and prints to stdout.  It should be comprised
of standard UNIX utilities (that is, it should not invoke any specialized C
programs
that you may consider writing). You MUST make use of pipes rather than using
files to store intermediate results.  Don't make this assignment
unnecessarily hard: the whole program can be done in ONE line (not counting
all the documentation lines).
--------------------------------------------------------------

I was thinking that (1) could be accomplished by using a tr line like ( tr
'\001-\011' '\136') but that replaces some of the non printing with the ^,
how would i get the letter in there and would I have to have a bunch of
those tr commands piped together just to accomplish (1)?

Some help on this would really really be appreciated as its due on Monday
and I've hit a brick wall on this one.

-mogrefy

2. DHCP and ip assigning

3. Need help wth rsh command!

4. kppp reports "/etc/ppp/options" file locked?

5. handling SIGINT in shell scripts when executing another shell script.

6. Angoss cant find libm.so.4 problem

7. UNIX Shell scripts... Help needed

8. How do I change my post heading?

9. Help! Gatewaying shell script needed!

10. UNIX Shell script.... help needed

11. Help: Shell script needs to encrypt a password

12. need help with shell script

13. shell script question. need help!