LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-28-2008, 06:02 AM   #1
hhanff
LQ Newbie
 
Registered: Oct 2008
Posts: 8

Rep: Reputation: 2
Start a program after the n-th linux boot up


Hello!

I developed a control program for an Imagenex 881A sonar head. As the whole system shall be deployed in the sea and run autonomously I would like to add the following functionality:

After the n-th boot-up of linux (e.g. after 5 boot-ups) not the standard contoll programm shall be started but a slightly modified version. The problem is that this shall only happen after the n-th boot-up.

How can I solve this problem? Cron does not seem to be very helpfull in my eyes. I was thinking of a shell script that saves the amount of boot-ups in a file and reads it after the n-th boot-up. Then after 5 boot-ups the modified version of my control program will be started.

Greetings,


Hendrik
 
Old 10-28-2008, 06:12 AM   #2
odcheck
Member
 
Registered: Aug 2006
Distribution: Fedora, CentOS, RHEL, Debian
Posts: 978

Rep: Reputation: 31
It must be something with lastlog, you're script must check this file and counts via the dates.
 
Old 10-28-2008, 06:19 AM   #3
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Have a quick look at the shutdown/start scripts and see how 'fsck' does it. A file is updated on each shutdown.
 
Old 10-28-2008, 07:27 AM   #4
hhanff
LQ Newbie
 
Registered: Oct 2008
Posts: 8

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by pinniped View Post
Have a quick look at the shutdown/start scripts and see how 'fsck' does it. A file is updated on each shutdown.
That's how I did it:

Code:
#! /bin/bash
START_MOD_AT=3
#AMOUNT_OF_BOOTUPS=0
if test -e .ser_config
then
  echo "ser.config exists..."
  read AMOUNT_OF_BOOTUPS < .ser_config
  echo "Nr:" $AMOUNT_OF_BOOTUPS

  if test $AMOUNT_OF_BOOTUPS -eq $START_MOD_AT ; then
    expr $AMOUNT_OF_BOOTUPS + 1 > .ser_config
    read AMOUNT_OF_BOOTUPS < .ser_config
    echo "Nr: "$AMOUNT_OF_BOOTUPS
	echo "Start modified program here!"
  else
    expr $AMOUNT_OF_BOOTUPS + 1 > .ser_config
    read AMOUNT_OF_BOOTUPS < .ser_config
	echo "Nr: "$AMOUNT_OF_BOOTUPS
	echo "Increment 1..."
  fi
  
else
  touch .ser_config
  echo 1 > .ser_config
  echo "... .ser_config created"
fi
 
Old 10-29-2008, 01:10 AM   #5
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Now you just have to modify your script to accept the start and stop arguments, just like every other service script in init.d. On start (link in rcS.d on Debian) you check the value, maybe run the program, and possibly set the value back to 0. On stop (rc0.d) you increment the value - but you have to do this at a time when the filesystem is still mounted r/w. At the moment your script is written so that everything happens at once (always incremented and checked), which is the wrong way to do it.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
start up program after boot SyCo123 Linux - General 2 03-10-2008 12:02 PM
Start program at boot The_paladin Debian 2 08-08-2006 01:30 PM
start program on boot AZaraT Linux - Newbie 6 06-26-2006 05:26 PM
How do I start a program on boot ? overproof Mandriva 4 04-22-2005 07:13 AM
program start at boot moonloader Slackware 4 03-08-2004 06:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:09 PM.

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