On Fri, Oct 02, 2026 at 08:36:07AM -0000, Crystal Kolipe wrote:
> On Fri, Oct 02, 2026 at 10:05:19AM +0200, dan wrote:
> > As I would tranform all in an rc script the problem remains changing the
> > prompt string from inside my test script..
> 
> In the rc script, write the string that you want to a file, say
> /etc/.net_status or something like that.
> 
> Then set the shell prompt _in your .profile_ to read that file:
> 
> export PS1="`cat /etc/.net_status`\$ "
> 
> Even better, instead of just running the network status script from rc, run it
> every 1 or 2 minutes from the root crontab and update /etc/.net_status.
> 

No need to reinvent the wheel, just use ifstated:

    net_up = '("netstat -fn | grep -qs default" every 5)'

    state auto {
      init {
        run "echo offline > /tmp/net_state"
      }
      if $online set-state online
      if $offline set-state offline
    }

    state online {
      init {
        run "echo online > /tmp/net_state"
      }
      if !$net_up set-state offline
    }

    state offline {
      init {
        run "echo offline > /tmp/net_state"
      }
      if $net_up set-state online
    }

(this is actually an *untested* abridged version of a more complex
config I use to also check whether my laptop is on the "home" network or
roaming, and decide whether to mount/umount NFS shares, bring the
wireguard interface up or down, etc)

-- 
     

Reply via email to