Welcome!
Important information
-- Spectre and Meltdown vulnerabilities
-- Change in MX sources

News
-- MX Linux on social media: here
-- Mepis support still here

Current releases
-- MX-17.1 Final release info here
-- antiX-17 release info here

New users
-- Please read this first, and don't forget to add system and hardware information to posts!
-- Here are the Forum Rules

running a script at boot time

Here is where users who have been using MEPIS awhile and know the basics of linux and MEPIS can ask questions.
Post Reply
Message
Author
User avatar
Adrian
Forum Veteran
Forum Veteran
Posts: 9241
Joined: Wed Jul 12, 2006 1:42 am

running a script at boot time

#1 Post by Adrian » Sun Jun 26, 2016 5:17 pm

I customized a MX-15 flashdrive with clonezilla package and use it for re-imaging various computers (BTW, never used persistence much before, it kicks ass, also like the F8 - save, BitJam did a great job :number1: ), I want to run a script at boot time after the network connects.

I tried link the script in /etc/rc.local but it doesn't seem to work, my impression is that it tries to run too soon, before the network is connected. I could add it in ~/.config/autostart which runs a bit later, but it might still not be late enough and I also need to run it as root.

What's the recommended solution for running a root script after the network is connected?

User avatar
kmathern
Forum Veteran
Forum Veteran
Posts: 9419
Joined: Wed Jul 12, 2006 2:26 pm

Re: running a script at boot time

#2 Post by kmathern » Sun Jun 26, 2016 6:11 pm

I don't know if it's the case for everybody but on my machine it looks like my wired connection is up and running just a little before the lightdm greeter gets displayed.

If that also applies in your case I wonder if you can set it up as one of the /etc/lightdm/lightdm.conf/*-setup-scripts ?

Code: Select all

$ grep 'setup-script'.*root /etc/lightdm/lightdm.conf 
# display-setup-script = Script to run when starting a greeter session (runs as root)
# greeter-setup-script = Script to run when starting a greeter (runs as root)
# session-setup-script = Script to run when starting a user session (runs as root)
It says 'runs as root' for all of them.

User avatar
BitJam
Forum Guide
Forum Guide
Posts: 2494
Joined: Sat Aug 22, 2009 11:36 pm

Re: running a script at boot time

#3 Post by BitJam » Sun Jun 26, 2016 7:28 pm

The exit status of the ping command should tell you if the network is up or not. Maybe do something like this:

Code: Select all

while true; do
    ping -c1 -W1 8.8.8.8 &>/dev/null || continue
    $YOUR_COMMAND
    exit
done
Notes:
  • 8.8.8.8 is the IP address of one of Google's DNS servers.
  • the "-c1" option says to only ping once
  • the "-W1" option sets the timeout for each ping to one second
The idea is that this code will poll your network status every one second and when it is able to reach 8.8.8.8 it will run your command and then exit. This code will run forever if the network never comes up. If you want it to give up after a minute then replace "while true;" with "for dummy in $(seq 60);".

I am absolutely delighted that you like some of the LiveUSB features. We've added more features and improvements in antiX-16 including the equivalent of "F8 Save" for the UEFI bootloader. On fast hardware I can boot to the desktop in under 10 seconds (Bash in 5 seconds) and I can do a frugal install and boot into the installed system in less than 30 seconds. Maybe this is some kind of record. With ordinary hardware and a usb-3 LiveUSB it takes about 15 -- 20 seconds to get to the desktop which is not too shabby.

For your purposes (re-imaging various computers) you might want to try live-remaster. It consolidates the persistence changes (and any other changes) by making a new linuxfs file. You need to reboot for the remastered linuxfs to take effect. You can run live-remaster again to clean up the old linuxfs file. I've been wanting to write a script that creates an iso file from a running Live system but I never got around to it. The idea is to skip the mksquashfs step by using the existing linuxfs file. I also wanted to write a script that updates the kernel on the LiveUSB.
Will I cry when it's all over?
When I die will I see Heaven?

User avatar
Adrian
Forum Veteran
Forum Veteran
Posts: 9241
Joined: Wed Jul 12, 2006 1:42 am

Re: running a script at boot time

#4 Post by Adrian » Sun Jun 26, 2016 7:44 pm

Thanks, I will try that check, I will probably ping a local server. I used live-remaster, works great. All the persistence/remaster tools are very useful, can't wait for the antiX-16 improvements to filter down to MX-16.

Maybe we can think about modifying mx-snapshot and skip mksquashfs step if live, I'm still a bit unclear how to create the ISO... the genisoimage command right now looks like:

Code: Select all

"genisoimage -gid 0 -uid 0 -allow-limited-size -l -V MX-Linux-live -R -J -pad -no-emul-boot -boot-load-size 4 -boot-info-table -b boot/isolinux/isolinux.bin -c boot/isolinux/isolinux.cat -o " + snapshot_dir.absolutePath() + "/\"" + filename + "\" . "  + work_dir + "/iso-2";
What do I need to modify to make it work in this scenario?

BTW, I made a small change to mx-snapshot, I added the GUI option to change the snapshot name, change that was long overdue.

User avatar
BitJam
Forum Guide
Forum Guide
Posts: 2494
Joined: Sat Aug 22, 2009 11:36 pm

Re: running a script at boot time

#5 Post by BitJam » Sun Jun 26, 2016 8:14 pm

Adrian wrote:What do I need to modify to make it work in this scenario?
There are a couple of things. Perhaps the most important and most pain-in-the-neck is to ensure that the iso file gets created on a real file system and not / on the live system. The command:

Code: Select all

df $FILE_OR_DIR | tail -n1 | cut -d" " -f1
should tell you. If it gives "aufs" or "overlay" then $FILE_OR_DIR is on the / file system which is not what you want (normally).

Then you are going to want to use the directory /live/boot-dev/ as the last parameter (I think) in the genisoimage call. You are also going to want to exclude persistence files, the /antiX/state/ directory and linuxfs.old and linuxfs.new. Generally you will want to exclude everything in the /antiX/ directory except: vmlinuz, initrd.gz, linuxfs and their md5 files. You will also want to exclude the /LiveUSB-Storage directory which is new for antiX/MX-16.
Will I cry when it's all over?
When I die will I see Heaven?

User avatar
Adrian
Forum Veteran
Forum Veteran
Posts: 9241
Joined: Wed Jul 12, 2006 1:42 am

Re: running a script at boot time

#6 Post by Adrian » Tue Jun 28, 2016 4:44 pm

Code: Select all

while true; do
    ping -c1 -W1 8.8.8.8 &>/dev/null || continue
    $YOUR_COMMAND
    exit
done
Tried this but I see on the terminal:

Code: Select all

ping: unknown host...
mount error: could not resolve...
The mount command is $YOUR_COMMAND, I don't understand how is executed, the continue should just start the do loop again, right?

User avatar
BitJam
Forum Guide
Forum Guide
Posts: 2494
Joined: Sat Aug 22, 2009 11:36 pm

Re: running a script at boot time

#7 Post by BitJam » Tue Jun 28, 2016 6:15 pm

I should have checked on Debian. Sorry about that. It works fine on Gentoo but the Debian version of ping is slightly different/broken. It exits true even if the ping fails. *sigh*

Maybe something like this will work:

Code: Select all

while true; do
    ping -c1 -W1 8.8.8.8 2>/dev/null | grep -q time= || continue
    $YOUR_COMMAND
    exit
done
Will I cry when it's all over?
When I die will I see Heaven?

User avatar
Adrian
Forum Veteran
Forum Veteran
Posts: 9241
Joined: Wed Jul 12, 2006 1:42 am

Re: running a script at boot time

#8 Post by Adrian » Tue Jun 28, 2016 6:19 pm

Wow, I didn't even bother to check that, it's so illogical.

Thanks!

User avatar
Adrian
Forum Veteran
Forum Veteran
Posts: 9241
Joined: Wed Jul 12, 2006 1:42 am

Re: running a script at boot time

#9 Post by Adrian » Wed Jun 29, 2016 10:36 am

It might be something else here, I tried "ping test" and it does return false.

Code: Select all

ping test; echo $?
ping: unknown host test
2

Post Reply

Return to “Regulars”