USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

UBUNTU: Can I run a script only at startup (not at shutdown)

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Installation and Bootloaders
View previous topic :: View next topic  
Author Message
fopetesl
Jr. Member


Joined: 27 Aug 2024
Posts: 85
Location: N.Yorkshire UK

PostPosted: Wed Jun 09, 2024 2:33 pm    Post subject: UBUNTU: Can I run a script only at startup (not at shutdown) Reply with quote

I'm trying (& failing) to write a script in /etc/init.d that only operates on boot up but NOT on shutdown.
The program I want to run does not accept any parameters.
This works
Code:
#!/bin/bash

test -f /var/www/html/moveit || exit 0

. /var/www/html/moveit

exit 0
but on shutdown and startup.

This doesn't
Code:
#!/bin/bash

test -f /var/www/html/moveit || exit 0

case "$1"
 start)
. /var/www/html/moveit
   ;;
  stop)
   ;;
  *)
esac

exit 0
either at startup or shutdown.

Obviously my newb systax but I can't see what is wrong Sad


Back to top
View user's profile Send private message
platinummonkey
Advanced Member


Joined: 01 Mar 2024
Posts: 732
Location: Texas

PostPosted: Wed Jun 09, 2024 3:59 pm    Post subject: Reply with quote

you can put things in your init scripts themselves too, or call them from such scripts and place that one in /usr/local/bin/ or something

your boot up scripts are like rc.local found in /etc



_________________
desktop - FreeBSD 7.2
laptop & server - Archlinux i686 kernel26 2.6.32.10-1
- TAMULinux-2.0.2-ALPHA
USB Boot - Archlinux i686 kernel26 2.6.32.10-1 USB boot
Back to top
View user's profile Send private message Visit poster's website AIM Address
fopetesl
Jr. Member


Joined: 27 Aug 2024
Posts: 85
Location: N.Yorkshire UK

PostPosted: Wed Jun 09, 2024 4:48 pm    Post subject: Reply with quote

Looks like I got it wrong here Sad
It seems the simple script did run at startup and shutdown but didn't have any response at startup.
The proggy "moveit" needs the LAN up and running so's it can communicate with a microcontroller.

At what point is, say eth0, initialised with a static IP?
And where would I now place "moveit"?


Back to top
View user's profile Send private message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Wed Jun 09, 2024 6:03 pm    Post subject: Reply with quote

In the Linux run level scheme, which, if I am not mistaken, follows the POSIX convention that comes, not from the BSD community, but from the UNIX System V community, run level 1 is the single user run level, run level 2 is multi-user, no networking, run level 3 is multi-user with networking, run level 5 is graphical user mode, networked. run level 0 specifies a halt on most systems and run level 6 specifies a reboot.

You would want to run network level commands in run levels 3 and 5 for most common Linux systems.

For differences in what run levels mean with various diverse operating system implementations, look at http://en.wikipedia.org/wiki/Runlevel for more details and variations.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
fopetesl
Jr. Member


Joined: 27 Aug 2024
Posts: 85
Location: N.Yorkshire UK

PostPosted: Thu Jun 10, 2024 7:09 am    Post subject: Reply with quote

masinick wrote:
In the Linux run level scheme, ..... run level 1 is the single user run level, run level 2 is multi-user, no networking, run level 3 is multi-user with networking, run level 5 is graphical user mode, networked. run level 0 specifies a halt on most systems and run level 6 specifies a reboot.
Thanks Smile But I have been through this .. I tried and put it at 90 with update-rc.d -f movitaction start 90 2 3 4 5 . so no start/shutdown response but LAN still not live, so It's still too early.

When does the NIC actually get initialised?


Back to top
View user's profile Send private message
VHockey86
Advanced Member


Joined: 12 Dec 2024
Posts: 988
Location: Rochester

PostPosted: Thu Jun 10, 2024 8:13 am    Post subject: Reply with quote

if you look in the /etc/rc*.d/ folders, what number does the "networking" script have in front of it? Is it higher than 90?



_________________
Main Desktops : Kubuntu 10.4. ArchLinux 64-bit. Windows7 64-bit. Windows XP 32-bit.

MacBook: OS X Snow Leopard (10.6)
Back to top
View user's profile Send private message
fopetesl
Jr. Member


Joined: 27 Aug 2024
Posts: 85
Location: N.Yorkshire UK

PostPosted: Thu Jun 10, 2024 8:21 am    Post subject: Reply with quote

VHockey86 wrote:
if you look in the /etc/rc*.d/ folders, what number does the "networking" script have in front of it? Is it higher than 90?
At present it's set to 90.

If I put in a wait loop (until NIC initialised) in my /init.d script will it not hold up the boot process?

And if The NIC initialisation is not concurrent then the script will never time out.


(You're up late, VH Shocked )


Back to top
View user's profile Send private message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Thu Jun 10, 2024 6:14 pm    Post subject: Reply with quote

At first glance, 90 would seem to be a high enough number to suffice - seems to me that a LOT of stuff happens concurrently at around the 20 level, so I am surprised that 90 is not enough. Rather than beat our heads there, I suspect that the real issue is somewhere else.

Can you give us an outline of the flow as you see it? Based on the simple descriptions, it does sound as if it ought to work, but clearly there are details that we aren't getting in this discussion - and perhaps a detail that you have overlooked as well. Perhaps a fresh description of your approach, detailing where files are located, which assumptions you are making, and so forth, will give YOU that "A Ha!" moment, and you'll say, "Why didn't I see that earlier?"

At least I hope that is what happens. Let us know a few more details and the approach that you are taking and maybe the answer will become clear to one (or all) of us.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
fopetesl
Jr. Member


Joined: 27 Aug 2024
Posts: 85
Location: N.Yorkshire UK

PostPosted: Fri Jun 11, 2024 8:40 am    Post subject: Reply with quote

masinick wrote:
... Let us know a few more details and the approach that you are taking and maybe the answer will become clear to one (or all) of us.
Thanks for the persistence Smile
It's a lab machine for measuring fibres.
The action I need is an almost once-ever.
The machine is set for transport in a "locked" situation.
On first power-up it needs to "unlock", e.g. ~/machine/moveit
The control circuit communicates via LAN which has a fixed/static IP.

In a 'normal' situation the user has a touchscreen GUI to take measurements, etc., with no access to command line functions.
It seems overly complicated to give the user the option to unlock. (if I could!)

So the present sequence is:
load mozilla in kiosk mode.
mozilla loads Flash GUI (but where? I can't find it).
user operates machine.

After this I can control the machine from a CLI without problem.

Note: I have once seen an error message from the init.d script immediately prior to login prompt which said it couldn't find the static IP address.
It is not logged in any of the 'normal' log files.
This suggests to me that the NIC/LAN is only initialised concurrent with or immediately after the virtual consoles are set up.

I tried to discover where the Flash GUI is loaded by Mozilla/localhost without success.

Note also that I am a C programmer with also some PHP but I am not a Flash programmer! I have had theis Flash GUI foisted upon myself Sad So the obvious option the have the GUI automagically run my script is not an option.

I'm not happy I have explained the sequence well so questions are welcome.


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Installation and Bootloaders All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse