Trying to read a file by line for a script
I'm having trouble with a script file I'm writing to disable services in the /etc/inetd.conf file. What I'm trying to do is back the file up, then read each line, look at the first word of the line, and add a # to the beginning of the line to comment it out. Here's the script:
#! /bin/ksh -x
#
# This script finds and disables services per the Unix configuration
# guidelines for Linux servers. - NH
#
cp /etc/inetd.conf /etc/inetd.conf.old
echo > /etc/inetd.conf.test
for line in `cat /etc/inetd.conf`
do
read first rest < $line
case "$first"
in
telnet) newline="\# $line";;
ftp) newline="\# $line";;
shell) newline="\# $line";;
login) newline="\# $line";;
klogin) newline="\# $line";;
exec) newline="\# $line";;
comsat) newline="\# $line";;
uucp) newline="\# $line";;
bootps) newline="\# $line";;
finger) newline="\# $line";;
systat) newline="\# $line";;
netstat) newline="\# $line";;
tfp) newline="\# $line";;
talk) newline="\# $line";;
ntalk) newline="\# $line";;
sadmind) newline="\# $line";;
uucpd) newline="\# $line";;
lpd) newline="\# $line";;
kpropd) newline="\# $line";;
stfsloader) newline="\# $line";;
*) newline="$line";;
esac
echo $newline >> /etc/inetd.conf.test
done
For some reason, it looks like it's getting each work of each line and placing it in the new file. I'm getting errors like this when the script runs:
+ ./config.sh[9]: root: cannot open
+ newline=root
+ echo root
+ 1>> /etc/inetd.conf.test
+ read first rest
+ 0< /usr/sbin/in.uucpd
+ newline=/usr/sbin/in.uucpd
+ echo /usr/sbin/in.uucpd
+ 1>> /etc/inetd.conf.test
+ read first rest
+ ./config.sh[9]: in.uucpd: cannot open
+ newline=in.uucpd
+ echo in.uucpd
+ 1>> /etc/inetd.conf.test
As far as I can tell, my read command is set up correctly but that seems to be the problem. Does anyone see my mistake?
|