Solved

Shell script (sh) execution from within rc.local failure

Posted on 2004-10-15
5
803 Views
Last Modified: 2012-06-21
Greetings

I have created a Linux-based, CD-based router operating system for my router machine.  I have done the same thing before for several internet connections, but this is the first time I have ever used a DSL-based PPPoE connection.  All of the other routers I've built have been for purely Ethernet-based configuration with routing for a block of IPs, a firewall, NAT, port forwarding, and a serial-based console(s).

This one is a little simpler, since it's for my home -- only one (dynamic) IP, a firewall, some NAT with port forwarding, but no routing or serial consoles.  But this is the first time I've had to get PPPoE working.

I have PPPoE working via Roaring Penguin PPPoE; the CD copies various config files to the RAMdisk at boot time, and when I log in I can run /usr/sbin/adsl-start and everything connects and works fine.

However, if I try to run /usr/sbin/adsl-start from rc.local, I get an endless loop of errors like:

expr: command not found, and
-gt: unary operator expected, etc.

I really need to run this at boot-time, and I also need to run it before I can run my firewall scripts, because obviously the firewall needs to use the ppp interface.

I have seen these errors before, but admittedly my job revolves more around the cursed world of Microsoft/.NET software development, and I have shied away from the realms of Linux systems administration for the past two years.  Is this a permissions problem?  The files are all CHMODed for executable; and of course the shell is too.  The config files are also all readable.

This is a 2.4.2x kernel, running on a heavily modified version of the "Sentry Firewall CD" (http://www.sentryfirewall.com).  But again, I don't think any of that is as important; the whole shebang works from a login shell but not from rc.local!

Should I try like /bin/bash /usr/sbin/adsl-start?  Even though adsl-start is configured to run with sh with !#/bin/sh?

As you can see I'm not even sure where to begin.  Any pointers would be appreciated.

Thanks for any help
-v2000
0
Comment
Question by:v2000
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:jacauc
ID: 12326439
My Shorewall firewall starts up before adsl-start,

do you use webmin on that machine? (well it'd make matters easier)
Try running the command "service adsl start" instead


otherwise, create an executable script file file with the following contents:

___________________COPY STARTS ON NEXT LINE______________________
#!/bin/sh
#
# adsl                     This script starts or stops an ADSL connection
#
# chkconfig: 2345 99 01
# description: Connects to ADSL provider # # LIC: GPL # # Copyright (C) 2000 Roaring Penguin Software Inc.  This software may # be distributed under the terms of the GNU General Public License, version # 2 or any later version.

# Source function library if it exists
test -r /etc/rc.d/init.d/functions && . /etc/rc.d/init.d/functions

# From AUTOCONF
prefix=/usr
exec_prefix=/usr

# Paths to programs
START=/usr/sbin/adsl-start
STOP=/usr/sbin/adsl-stop
STATUS=/usr/sbin/adsl-status
case "$1" in
    start)
        gprintf "Bringing up ADSL link"

      $START
      if [ $? = 0 ] ; then
            touch /var/lock/subsys/adsl
              echo_success
      else
            echo_failure
      fi
        echo ""
        ;;

    stop)
        gprintf "Shutting down ADSL link"

      $STOP > /dev/null 2>&1
      if [ $? = 0 ] ; then
            rm -f /var/lock/subsys/adsl
              echo_success
      else
            echo_failure
      fi
        echo ""
        ;;

    restart|reload)
      $0 stop
      $0 start
      ;;

    status)
      $STATUS
      ;;

    *)
        gprintf "Usage: adsl {start|stop|restart|reload|status}\n"
        exit 1
esac

exit 0



___________________COPY ENDS HERE______________________

now save this file somewhere:
and then do a
chmod 700 /path/to/script
now in rc.local you can start it with the command:
/path/to/script start
instead


Hope this makes sense
Thanks
J

0
 
LVL 6

Accepted Solution

by:
de2Zotjes earned 200 total points
ID: 12326537
The 2 errors that you state are most likely caused by referring to variables that are not set ( the -gt case) and calling programs that are not in the path (expr: command not found)

You could start your search for the culprits by dumping you environment when the adsl-start starts. Make the first line: env > /tmp/adsl_start_env

You can compare this environment with the one you have when you have a prompt:

env > /tmp/prompt_env
cd /tmp
diff prompt_env adsl_start_env | less

See what differs between the 2 and think about what consequences that might have for your start-script.

i realize this is not a solution, but it is more of a recipe to get to a solution :-)
0
 
LVL 1

Author Comment

by:v2000
ID: 12327767
Excellent.  I apologize for my idiocy; I never realized "expr" was a command.  But your response led me to check, and indeed, it was residing outside of the PATH for rc.local.  So I extended the PATH and exported it before I ran adsl-start, and everything worked fine.

Thanks!
0
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 12486677
Would you mind closing the question ?
0
 
LVL 1

Author Comment

by:v2000
ID: 12486688
Sorry, I'm a total moron.  I guess the medication is getting to me :-)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question