LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-23-2007, 12:55 PM   #1
Runge_Kutta
Member
 
Registered: Jul 2006
Location: H-town, TX
Distribution: SuSE10.1, Ubuntu 9.10, RHEL-4-WS, Fedora Core 6, CentOS 5.x, Fedora 13
Posts: 35

Rep: Reputation: 16
Post bash "unexpected end of file" script error


Hi guys!

I'm getting an "unexpected end of file" script error from the following code below.

I have already tried fixing the "# !/bin/bash" line to "#/bin/bash/," "/bin/ksh," and other variants. I've also tried adding "exit","exit(1)","exit(0)", to the end of the following script. Also, I've made sure bash and ksh are in the /bin/ directory.
Any change that I do simply gives the same following output w/error:
"*Allowing root logins via rlogin and rsh
./root_add2:line 41: syntax error: unexpected end of file"

. . .with "line 41" being the last line of the script file nomatter if the file size of the script ends up being 38 or 42 lines.

Other things you guys might need to know:
I'm running this script on Fedora Core 6 x86_64 system with the intent of migrating the script to a rhel-4-ws blade/node. My intent is to remote login as root account using rlogin command to the rhel-4-ws blade/node from another machine/node - I can already remote login as another user to the rhel-4-ws blade/node using an account other than root.

Code:
# !/bin/bash
# To allow root login via rlogin/rsh, add 'rlogin' and 'rsh' entries
# to /etc/securetty
echo "* Allowing root logins via rlogin and rsh"
if grep '^rlogin' /etc/securetty > /dev/null; then \
  echo "** rlogin is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
fi #added
rlogin
EOF
#fi - changed!
if grep '^rsh' /etc/securetty > /dev/null; then \
  echo "** rsh is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
fi #added
rsh
EOF
#fi - changed
cat > /root/.rhosts << EOF
master root
EOF
#
# Enable rsync, rlogin, and rsh
echo "* Enabling rsync, rlogin, and rsh"
chkconfig rsync on
chkconfig rlogin on
chkconfig rsh on
#
# Update /etc/aliases so someone gets root's mail
echo "* Updating /etc/aliases"
if grep '^root:' /etc/aliases > /dev/null; then \
  echo "** root is already contained in /etc/aliases"
else \
  cat >> /etc/aliases << EOF
fi #added
root:  localuser@node01
EOF
exit
. . . the original code looked like the following - part of a kickstart post configuration script
(I just wanted this part of the code to work).

Code:
%post
#/bin/bash
# . . . a bunch of code

# To allow root login via rlogin/rsh, add 'rlogin' and 'rsh' entries
# to /etc/securetty
echo "* Allowing root logins via rlogin and rsh"
if grep '^rlogin' /etc/securetty > /dev/null; then \
  echo "** rlogin is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
rlogin
EOF
fi
if grep '^rsh' /etc/securetty > /dev/null; then \
  echo "** rsh is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
rsh
EOF
fi
cat > /root/.rhosts << EOF
master root
EOF
#
# Enable rsync, rlogin, and rsh
echo "* Enabling rsync, rlogin, and rsh"
chkconfig rsync on
chkconfig rlogin on
chkconfig rsh on
#
# Update /etc/aliases so someone gets root's mail
echo "* Updating /etc/aliases"
if grep '^root:' /etc/aliases > /dev/null; then \
  echo "** root is already contained in /etc/aliases"
else \
  cat >> /etc/aliases << EOF
root:  localuser@node01
EOF
the whole kickstart post script looks like this (it's kind of long):

Code:
%post
#/bin/bash
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH
#
# Penguin Cluster Node Assimilation Script
echo "Commencing Penguin Cluster Node Assimilation"
#
# Setup hosts table
echo "* Building /etc/hosts"
cat > /etc/hosts << EOF
127.0.0.1    `hostname` localhost.localdomain localhost
#
192.168.0.1   node01 master
192.168.0.2   node02
192.168.0.3   node03
  .
  .
  .
192.168.0.64  node64
EOF
#
# Configure ipchains for needed service, block everything else
echo "* Reconfiguring the firewall rules"
cat > /etc/sysconfig/ipchains << EOF
:input ACCEPT
:forward ACCEPT
:output ACCEPT
-A input -s 0/0 -d 0/0 22 -p tcp -y -j ACCEPT
-A input -s 0/0 -d 0/0 -i lo -j ACCEPT
-A input -s 0/0 -d 0/0 -i eth0 -j ACCEPT
-A input -s 0/0 -d 0/0 -p tcp -y -j REJECT
-A input -s 0/0 -d 0/0 -p udp -j REJECT
EOF
/etc/rc.d/init.d/ipchains restart
#
# Configure ntp and set the correct time before going any further
echo "* Configuring and starting time service"
cat > /etc/ntp.conf << EOF
restrict default noquery notrust nomodify
restrict 127.0.0.1
restrict 192.168.0.0 mask 255.255.0.0
server 192.168.0.1
driftfile /etc/ntp.drift
logfile /var/log/ntp.log
EOF
cat > /etc/ntp/step-tickers << EOF
192.168.0.1
EOF
chkconfig ntpd on
/etc/rc.d/init.d/ntpd start
#
# Setup /etc/hosts.equiv
echo "* Building /etc/hosts.equiv"
cat > /etc/hosts.equiv << EOF
node01
node02
node03
  .
  .
  .
node64
EOF
#
# Setup NFS mounts
echo "* Establishing NFS mounts"
mkdir -p /home
mkdir -p /u1
if test -f /etc/fstab.assim-save; then \
  echo "** WARNING: Modifying previously-saved fstab file instead of the current one"
else \
  cp -p /etc/fstab /etc/fstab.assim-save
fi
cat > /etc/fstab << EOF
`cat /etc/fstab.assim-save`
node01:/home  /home  nfs    soft,bg,intr  0 0
node01:/u1    /u1    nfs    soft,bg,intr  0 0
EOF
mount -at nfs
#
# Configure a serial console
echo "* Configuring for serial console"
if grep '^co:' /etc/inittab > /dev/null; then \
  echo "** Serial console already configured"
else \
  cat >> /etc/inittab << EOF
# Serial console since this machine has no head
co:2345:respawn:/sbin/agetty ttyS0 9600 vt100
EOF
fi
if grep '^ttyS0' /etc/securetty > /dev/null; then \
  echo "** ttyS0 is already contained in /etc/securetty";
else \
  cat >> /etc/securetty << EOF
ttyS0
EOF
fi
#
# Update /etc/hosts.allow and /etc/hosts.deny
echo "* Setting up /etc/hosts.allow and /etc/hosts.deny"
cat > /etc/hosts.allow << EOF
#
# hosts.allow   This file describes the names of the hosts which are
#              allowed to use the local INET services, as decided
#              by the '/usr/sbin/tcpd' server.
#

ALL: 192.168.0.
EOF
cat >> /etc/hosts.deny << EOF
#
# hosts.deny   This file describes the names of the hosts which 
#              are *not* allowed to use the local INET services, 
#              as decided by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!

ALL: ALL
EOF
#
# To allow root login via rlogin/rsh, add 'rlogin' and 'rsh' entries
# to /etc/securetty
echo "* Allowing root logins via rlogin and rsh"
if grep '^rlogin' /etc/securetty > /dev/null; then \
  echo "** rlogin is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
rlogin
EOF
fi
if grep '^rsh' /etc/securetty > /dev/null; then \
  echo "** rsh is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
rsh
EOF
fi
cat > /root/.rhosts << EOF
master root
EOF
#
# Enable rsync, rlogin, and rsh
echo "* Enabling rsync, rlogin, and rsh"
chkconfig rsync on
chkconfig rlogin on
chkconfig rsh on
#
# Update /etc/aliases so someone gets root's mail
echo "* Updating /etc/aliases"
if grep '^root:' /etc/aliases > /dev/null; then \
  echo "** root is already contained in /etc/aliases"
else \
  cat >> /etc/aliases << EOF
root:  localuser@node01
EOF
newaliases
fi
#
# useradd may be used to establish user accounts on the compute node.
# Alternatively, the master node may provide user/group databases using rsync
# after the installation process is complete.
#
# Install my favorite analysis package
rpm -i /u1/packages/analpack-1.0-5.i386.rpm
# Install my favorite commercial compiler
tar xzpf /u1/packages/xyz-f90.tar.gz
#
echo "Penguin Cluster Node Assimilation Complete"
exit
sorry for the long post, just wanted to make sure everyone had enough info to sink their teeth into this problem. I need fresh eyes to go over this script ( probably some dumb syntactical error, as this is my first try at scripting under linux) while I'm out for lunch :-)
 
Old 05-23-2007, 02:00 PM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Your
Code:
fi #added
will go to file, not to interpreter. And the last 'else' is not closed because of this.

By the way, you do not want to add rlogin to securetty. Rlogin goes entirely unencrypted. So it is way too easy to intercept and then abuse. And logging in as root by rlogin means actively seeking troubles. Root login console should be acquired - if needed remotely - by a 'su -' from an ssh session.. Notice that original script marked ttyS0 as secure - it is COM port that requires physical access to the back side of computer. Not just physical access to any wire going to the same switch as the box you'll use to login from...
 
Old 05-23-2007, 02:06 PM   #3
lakris
Member
 
Registered: Sep 2004
Location: Stockholm, Sweden
Distribution: Ubuntu, RedHat, SuSe, Debian, Slax
Posts: 102

Rep: Reputation: 15
The problem lies in the method of representing linefeed/carriage return in text files between different operating systems. Try to use the utility
dos2unix
on the file on Your Linux-machine to fix this. I guess You created this on a Windows-machine and copied it to the Linux-machine?

Just my few cents.
/L
 
Old 05-23-2007, 02:12 PM   #4
Runge_Kutta
Member
 
Registered: Jul 2006
Location: H-town, TX
Distribution: SuSE10.1, Ubuntu 9.10, RHEL-4-WS, Fedora Core 6, CentOS 5.x, Fedora 13
Posts: 35

Original Poster
Rep: Reputation: 16
yea, about that login as root thing (I forgot to mention it as I knew someone would bring it up and I didn't want anyone wasting any brain power about it):

I just walked on the job two weeks ago - I know that logging in as root is bad (I'm close to a reformat on another blade/node because of this - people are abusing the system): the server was configured this way before I got here and that is how people have been using/logging into the server nodes. I'll have a chance to reconfigure the server login process later; but for now, they (clients) want it to work this way - btw, the server is connected (at least, supposed to be) to an 'intranet' switch which is not connected to the internet/outside world in anyway (and only about ten people use this server system for intensive calculation purposes).

So yea, if anyone knows of an easier way to accomplish this (remote login as root to rhel-4-ws system) then please let me know - otherwise, help me in fixing above script.

Quote:
Originally Posted by lakris
The problem lies in the method of representing linefeed/carriage return in text files between different operating systems. Try to use the utility
dos2unix
on the file on Your Linux-machine to fix this. I guess You created this on a Windows-machine and copied it to the Linux-machine?

Just my few cents.
/L
the script comes from a kickstart post script used to configure some settings after an installation of Linux (i think rhel), so no, above script does not originate in dos (see last code segment in 1st post).

-----------------------------------------------------------------------------------------
ignore my previous statement lakris as I just realized what you said/meant. I'll try both your windows2unix method and what raskin pointed out as lines of code that I carelessly am sending to file (I think I need to move the "fi" statements after "EOF"? - Ok, I go try now . . .
-----------------------------------------------------------------------------------------
Update:

I tried the above and I still get the error. Script, now, looks like below:

Code:
# !/bin/bash
# To allow root login via rlogin/rsh, add 'rlogin' and 'rsh' entries
# to /etc/securetty
echo "* Allowing root logins via rlogin and rsh"
if grep '^rlogin' /etc/securetty > /dev/null; then \
  echo "** rlogin is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
rlogin
EOF
fi# - changed back!
if grep '^rsh' /etc/securetty > /dev/null; then \
  echo "** rsh is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
rsh
EOF
fi# - changed back!
cat > /root/.rhosts << EOF
master root
EOF
#
# Enable rsync, rlogin, and rsh
echo "* Enabling rsync, rlogin, and rsh"
chkconfig rsync on
chkconfig rlogin on
chkconfig rsh on
#
# Update /etc/aliases so someone gets root's mail
echo "* Updating /etc/aliases"
if grep '^root:' /etc/aliases > /dev/null; then \
  echo "** root is already contained in /etc/aliases"
else \
  cat >> /etc/aliases << EOF
root:  localuser@node01
EOF
fi #Added

Last edited by Runge_Kutta; 05-23-2007 at 02:44 PM.
 
Old 05-23-2007, 03:01 PM   #5
lakris
Member
 
Registered: Sep 2004
Location: Stockholm, Sweden
Distribution: Ubuntu, RedHat, SuSe, Debian, Slax
Posts: 102

Rep: Reputation: 15
-----------------------------------------------------------------------------------------
ignore my previous statement lakris as I just realized what you said/meant. I'll try both your windows2unix method and what raskin pointed out as lines of code that I carelessly am sending to file (I think I need to move the "fi" statements after "EOF"? - Ok, I go try now . . .[/QUOTE]
***************************
Yeah, and sorry, I was too hot on the kbd as well, there are actual syntax errors in your script. What i hinted at usually manifest itself in "command not found" error.
The first cat statement actually appends "fi #added" to the file /etc/securetty, which probably isn't what You wanted and as Raskin said, leaves the if-then-else incomplete. It is important where You put the delimiters, if-then-else-fi. And the magic that EVERYTHING between the two EOF (and the second one must start a line) is regarded as one string of bytes/characters.
You should do something like (for this particular piece of code)
<code>
#!/bin/bash
# To allow root login via rlogin/rsh, add 'rlogin' and 'rsh' entries
# to /etc/securetty
echo "* Allowing root logins via rlogin and rsh"
if grep '^rlogin' /etc/securetty > /dev/null; then # Searches for a line starting with rlogin
echo "** rlogin is already contained in /etc/securetty"
else
#Next command echoes everything between the two EOF to the file /etc/securetty
cat >> /etc/securetty << EOF
rlogin
EOF
fi
</code>
etc...

But, I feel it would be cleaner to do
<code>
if grep '^rlogin' /etc/securetty > /dev/null; then
echo "** rlogin is already contained in /etc/securetty"
else
echo rlogin >> /etc/securetty
fi
</code>
More obvious in a way. EOF is usually used when You have A LOT of text to output. Using >> (append) is important, so You don't use > (output) which will overwrite the file.
 
Old 05-23-2007, 03:18 PM   #6
Runge_Kutta
Member
 
Registered: Jul 2006
Location: H-town, TX
Distribution: SuSE10.1, Ubuntu 9.10, RHEL-4-WS, Fedora Core 6, CentOS 5.x, Fedora 13
Posts: 35

Original Poster
Rep: Reputation: 16
Success!!!

Everything now works, and I was able to run the script on the target machine/node and now users are able to log in easily as root (even though it's still a bad idea - but hey, that's what they want )

apparently,one of the other changes I needed in the script was a space between the "fi" statement and the comment "# - changed back"

raskin - thanks!
lakris! welcome to LQ.org!


Thanks guys for all the help, and the final product came out looking like this:

Code:
#!/bin/ksh
# To allow root login via rlogin/rsh, add 'rlogin' and 'rsh' entries
# to /etc/securetty
echo "* Allowing root logins via rlogin and rsh"
if grep '^rlogin' /etc/securetty > /dev/null; then \
  echo "** rlogin is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
rlogin
EOF
fi # - changed back!
if grep '^rsh' /etc/securetty > /dev/null; then \
  echo "** rsh is already contained in /etc/securetty"
else \
  cat >> /etc/securetty << EOF
rsh
EOF
fi # - changed back!
cat > /root/.rhosts << EOF
master root
EOF
#
# Enable rsync, rlogin, and rsh
echo "* Enabling rsync, rlogin, and rsh"
chkconfig rsync on
chkconfig rlogin on
chkconfig rsh on
#
# Update /etc/aliases so someone gets root's mail
echo "* Updating /etc/aliases"
if grep '^root:' /etc/aliases > /dev/null; then \
  echo "** root is already contained in /etc/aliases"
else \
  cat >> /etc/aliases << EOF
root:  localuser@node01
EOF
fi #Added

Last edited by Runge_Kutta; 05-23-2007 at 03:23 PM.
 
Old 05-23-2007, 03:36 PM   #7
lakris
Member
 
Registered: Sep 2004
Location: Stockholm, Sweden
Distribution: Ubuntu, RedHat, SuSe, Debian, Slax
Posts: 102

Rep: Reputation: 15
Nice!
The fi# was the culprit, I didn't realize.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
FC5: File system Crash, "Unexpected inconsistancy ... " SparceMatrix Fedora 1 09-04-2006 05:04 AM
Oracle 10g says "end of file" cyclic redundancy error mmjulian Linux - Software 2 05-22-2004 02:57 AM
Can I redirect script output to a file without ">> $LOGFILE" at the end of each line davee Linux - General 1 12-19-2003 05:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration