Linux Script Examples
A makefile script example
Scripting that checks a file and modifies it if required. Since it is from a makefile, this file is similar to a normal script but is slightly modified with lines that end with ";\" characters. This section demonstrates modification of the rc.local file from a makefile so a script program, "printst", may be run in the background when the system starts. The variable "BINLOC" is defined earlier with the line "BINLOC = /usr/local/tmp". See the section on "Making Packages" under the header "Making makefiles".
# Add the path for $(BINLOC) to the /etc/rc.d/rc.local file
@PATHIN=`grep "path=" /etc/rc.d/rc.local | grep "$(BINLOC)"`; \ # See if the BINLOC path is set in the rc.local file
HEADER=""; \
if \
[ -z "$$PATHIN" ]; \
then \
echo Adding $(BINLOC) to path in /etc/rc.d/rc.local; \
echo >> /etc/rc.d/rc.local; \
echo "###### Added by Print Service Install on `date` by `whoami`" >> /etc/rc.d.rc.local; \
HEADER=Y; \
echo "export PATH=\$$PATH:$(BINLOC)" >> /etc/rc.d.rc.local; \
else \
echo $(BINLOC) already set in path in file /etc/rc.d/rc.local; \
fi; \
PRINTST=`grep -i "printst &" /etc/rc.d/rc.local`; \ # See if the string printst is in the rc.local file
if \
[ -z "$$PRINTST" ]; \
then \
echo Adding printst command to /etc/rc.d/rc.local file; \
if \
[ -z "$$HEADER" ]; \
then \
echo >> /etc/rc.d.rc.local; \
echo "###### Added by Print Service Install on `date` by `whoami`" >> /etc/rc.d.rc.local; \
HEADER=Y; \
fi; \
echo "printst &" >> /etc/rc.d.rc.local; \
else \
echo Already have printst command in /etc/rc.d/rc.local file; \
fi; \
if \
[ -n "$$HEADER" ]; \
then \
echo "###### End of Print Service Install Section ######" >> /etc/rc.d.rc.local; \
echo >> /etc/rc.d.rc.local; \
fi;
|