How to make a script run constantly on IGEL OS?


Hello, I have a question regarding Custom Commands in UMS. I have written up a short script to run at Initialization under the Base custom commands. The script is meant to pass the proper username and password for the wifi, so that the thin client can connect to the SSID defined in the script. I have since had to add an additional SSID to the script, so if one is not being broadcast, the script checks the other and then connects to that instead.

Learn more, read the entire thread inside the IGEL Community o Slack

My question is regarding how often this would run in firmware customizations. I would need the script to be checking constantly, in the event one SSID stops broadcasting, the script kicks in and checks the other SSID and connects again. I’m trying to figure out if this configuration in UMS would constantly be checking, or if there’s a location I can run this script so it runs at startup and then runs again if wifi is disconnected.


Basically, the script would run only during boot up (Initialization), having it working in a loop is a little bit more complex (while true, in case, If then else) but should be the way how to setup the script.

As an alternative you could think about using

your script in a dispatcher.d way:

manpages.ubuntu.com/manpages/xenial/man8/NetworkManager.8.html

Does that help?


Even if I were to make it an “if then else” (I already have an ‘if then’ statement) wouldn’t that still only run at initialization? I understand that the scripts get called based on their location in the config.


Yes, you would have to create a loop with a sleep since it‘s got started one time.

I like the dispatcher.d way, since your script would be invoked as soon as the network state change.


So a lopp with a sleep timer at the “Initialization” base of the config, would technically still work? As in, the script may get continuously run or called upon to check the SSID ?

Another idea I’m curious about – I made a profile created for the WLAN SSIDs – I configured – Network>Lan Interfaces> Wireless>Default wifi and Additional wifi

And put both SSID’s I’d like to use.


If your script gets called there, yes, it will be run as root until your script ends.


^Thank you for that part.

If I passthrough the username and password for both SSID’s at startup using the initialization config, and have both networks defined in the location i mentioned above, would both SSID’s have the username and password passing through right away and be ok to connect later, if one SSID were to drop the other connect? I apologize if I’m confusing the description.


It depends I think, can you share your script anonymized?


Yes

It’s actually something I found through IGEL Github I think, I just modified it slightly –

#!/bin/bash

Domain=”XX\”

SSID=$(iwgetid wlan0 -r)

RENAMEVAR=$(dmidecode -t system | grep -i “serial” | cut -c 17-)

HOSTNAME=$(hostname)

if [ “$SSID” == “XX” ] && [ “$RENAMEVAR” != “$HOSTNAME” ]

then

setparam network.interfaces.wirelesslan.device0.wpa.identity “$Domain$RENAMEVAR”

killall postsetupd

write_rmsettings

fi

sleep 1

SSID=$(iwgetid wlan0 -r)

RENAMEVAR=$(dmidecode -t system | grep -i “serial” | cut -c 17-)

HOSTNAME=$(hostname)

if [ “$SSID” == “XX” ] && [ “$RENAMEVAR” != “$HOSTNAME” ]

then

setparam network.interfaces.wirelesslan.device0.wpa.identity “$RENAMEVAR”

killall postsetupd

write_rmsettings

fi

I can definitely wrap it in a ‘while true’ loop, but I’m not the best at bash.


Just to give you an example here is a simple while true loop, I’m working on. That was a request from @member, I’m still not having functional, but it may help you:

#!/bin/bash

LOG=/var/log/mylog.log

SECONDS=3

restart_networking() {

su user -c “/bin/bash /bin/start-wireless-manager”

}

for i in $@; do

echo “$i-UP!” > $LOG.$i

done

while true; do

for i in $@; do

ping -c 1 $i > /dev/null

if [ $? -ne 0 ]; then

STATUS=$(cat $LOG.$i)

if [ $STATUS != “$i-DOWN!” ]; then

echo “`date`: ping failed, $i host is down!”

restart_networking

fi

echo “$i-DOWN!” > $LOG.$i

else

STATUS=$(cat $LOG.$i)

if [ $STATUS != “$i-UP!” ]; then

echo “`date`: ping OK, $i host is up!”

fi

echo “$i-UP!” > $LOG.$i

fi

done

sleep $SECONDS

done

Regarding your question: yes, from what I’m seeing the wpa identity is SSID independant so it should be used by both SSIDs, I guess


I appreciate that. I’ll have to dig further to understand the while loop for my configuration. I’ve been able to roughly test what I currently have and found that it connects to both SSID’s when one is missing. However, I think it’s mostly dependent on which SSID I had set as primary at the time. I’ll have to figure out a better solution to the initialization script.

Thank you for the help!

Continue reading and comment on the thread ‘How to make a script run constantly on IGEL OS?’.  Not a member? Join Here!

Learn more, search the IGEL Knowledge Base



Ask a question or comment on the above message thread?

Join or log in to the IGEL Community to ask us anything and meet other IGEL customers, partners, and EUC enthusiasts.

Submit a question, or Join Today!


Popular Message Threads


Categories & Tags: