LinuxQuestions.org
Help answer threads with 0 replies.
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 02-18-2015, 08:19 PM   #1
pazu
LQ Newbie
 
Registered: Oct 2014
Posts: 8

Rep: Reputation: Disabled
Question Starting Script on boot - what am I doing wrong?


Hi all,

Hopefully its an easy fix, I'm trying to start a script at startup that will run forever (while system is online).

It is a SUSE base OS (Sophos UTM box), but I don't think that should matter too much.

I have a script, called statupdate

I have located it in /etc/init.d/

I have given it execute permissions

I have then put in a link to it under /etc/init.d/RC3.d/S99statupdate

This worked, but the system boot sequence never finished because the script started kept looping, preventing the system boot sequence to continue.

I then created another script called startupdate

that script simply started the main statupdate script. I tried with the following:

./statupdate &

OR

nohup ./statupdate &

I swapped out the S99statupdate with S99startupdate (and gave it execute permissions)

The exact same issue occured.

Can anyone point out what I'm doing wrong?

Cheers,
Pazu
 
Old 02-19-2015, 04:16 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
1. post the script(s)
2. look at how other initscripts are written and copy the design
 
Old 02-19-2015, 04:28 AM   #3
pazu
LQ Newbie
 
Registered: Oct 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
Actual script I want to run at boot is:
Code:
#!/bin/bash          
while :
do
IP='10.0.0.185'
DN=$(S=1; F=/sys/class/net/ppp0/statistics/rx_bytes; X=`cat $F`; sleep $S; Y=`cat $F`; BPS="$(((Y-X)/S))"; echo $BPS)
UP=$(S=1; F=/sys/class/net/ppp0/statistics/tx_bytes; X=`cat $F`; sleep $S; Y=`cat $F`; BPS="$(((Y-X)/S))"; echo $BPS)
CPU=$(uptime | grep -oh "load average: [0-9].[0-9][0-9]")
CPU=$(echo $CPU | sed -r 's/^.{14}//')
UPTIME=$(cat /proc/uptime)
UPTIME=$(echo $UPTIME | cut -f1 -d" ")
#echo $DN
#echo $UP
#echo $CPU
#echo $UPTIME
curl $IP/?$DN/$UP/$CPU/$UPTIME!
sleep 1
done
Current start script is:

Code:
#!/bin/bash          
./statupdate &
are you able to point me at other init scripts? I have had a look at some on the server itself, but they all seem way more complicated that I have seen posted online (albeit they work!)
 
Old 02-19-2015, 05:08 AM   #4
pazu
LQ Newbie
 
Registered: Oct 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
I suspect I've completed missed the point of the init script, the skeleton/readme isn't on the box i'm working on so I got a tad lost.

If someone can point me in the direction of a step by step guide for init scripts that would be great.

I have found a few guides such as:

http://www.linux.com/learn/tutorials...h-init-scripts

https://en.opensuse.org/openSUSE:Packaging_init_scripts

But they both refer to the application or executable, can I just use the script i want to run as the executable?

Regards,
Pazu
 
Old 02-19-2015, 05:20 AM   #5
pazu
LQ Newbie
 
Registered: Oct 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
I have tried the following but get an error 'unknown service' when trying to add with chkconfig

Code:
#!/bin/bash
#
# Run-level Startup script for the LCD Stat Updater
#
# chkconfig: 345 91 19
# description: Startup/Shutdown LCD Stat Updater

# if the executables do not exist -- display error

if [ ! -f /etc/init.d/statupdate ]
then
        echo "LCDStatusMon startup: cannot start"
        exit 1
fi

# depending on parameter -- startup, shutdown, restart 
# of the instance and listener or usage display 

case "$1" in
    start)
        # LCDStatusMon  startup
        echo -n "Starting LCD Status Monitor: "
        /etc/init.d/statupdate
        echo "OK"
        ;;
    stop)
 	# LCDStatusMon shutdown
        echo -n "Shutdown LCD Status Monitor: "
        pkill -f statupdate
        echo "OK"
        ;;
    reload|restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart|reload"
        exit 1
esac
exit 0
 
  


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
[SOLVED] how to starting up a script or a program at boot time golden_boy615 Linux - General 2 05-08-2010 03:56 PM
Having trouble starting network at boot-up from a script. Zombie13 Puppy 3 02-11-2009 01:06 PM
starting a programme from boot script in Etch knobby67 Debian 10 02-05-2008 03:38 AM
starting the script at boot time hudy_rob Mandriva 4 12-09-2004 10:29 AM
starting a script on boot jax8 Linux - Newbie 1 03-19-2004 10:38 PM

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

All times are GMT -5. The time now is 04:18 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