Operating System - HP-UX
1847193 Members
4235 Online
110263 Solutions
New Discussion

Re: Script running at startup

 
SOLVED
Go to solution
Geert Joosten
Occasional Advisor

Script running at startup

Hi,
We have a little script that must keep on running. On the commandline this is started with: # nohup dclabel1 &
Placing this in /sbin/init.d it results in a lot of processes (too many for the system).
What's is the right way to start such process? The content of the script dclabel1 is:
while true
do
cat < /labels/dclabel1_printer | lp -ddclabel1 1>/dev/null 2>/dev/null
done

Thanks in advance,
Geert.
5 REPLIES 5
Mark Greene_1
Honored Contributor
Solution

Re: Script running at startup

Add this entry to /etc/inittab:

catlabels:3:boot:/fullpathtoscript/dclabel1


where you replace "fullpathtoscript" with the appropriate directory structure. The next time you reboot, it will start the script in the background.

mark
the future will be a lot like now, only later
Marco Santerre
Honored Contributor

Re: Script running at startup

I don't think that the logic behind your script is that bad, but you probably should do something so that it doesn't trigger a cat process every second or so..

In my mind, you could probably be better off using a cron every five minutes or by issuing a wait command after your cat so that your while stops to give time to the cat command to process.
Cooperation is doing with a smile what you have to do anyhow.
John Carr_2
Honored Contributor

Re: Script running at startup

Hi

you definetly need to put a sleep command into the script to stop it going mad or use crontab which is the easiest way :-) John.
Michael Schulte zur Sur
Honored Contributor

Re: Script running at startup

Hi,

what is /labels/dclabel1_printer ?
Is that a pipe? How do you make sure, you don't try to print half created labels? Otherwise I agree on using crontab. You could let the script running forever with a sleep and check the existence of the process in a crontab job and if necessary restart it.

greetings,

Michael
Mark Greene_1
Honored Contributor

Re: Script running at startup

If we want to get into rewriting the script, try something like this:

while true
do
if [[ -r /labels/dclabel1_printer ]]; do
lp -ddclabel1 /labels/dclabel1_printer 1>/dev/null 2>&1
rm /labels/dclabel1_printer
fi
done

This eliminates the useless use of cat, only prints when there's something to print, and will run indefinitely. I'd also suggest routing the lp output to a log file incase you have errors, but that's just me.

mark
the future will be a lot like now, only later