Solved

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

Posted on 2004-10-15
5
795 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now