This is useful if you don't want lots of programs running until you get a network connection. I use it for gmail notifier, which gives error messages if there's no network. There's only easy mode at the moment, as that's what I'm using.
sudo kwrite /etc/network/if-up.d/mynetstart
#!/bin/bash export DISPLAY=:0.0 MYNETSTART=/home/user/.network-autostart if [ -x $MYNETSTART ]; then su -c "$MYNETSTART" user fi
sudo chmod 0755 /etc/network/if-up.d/mynetstart
sudo ln -s /etc/network/if-up.d/mynetstart /etc/ppp/ip-up.d/
kwrite ~/.network-autostart
#!/bin/bash logger -p user.info "Network Autostart Script starting" if [ "`/sbin/ifconfig | grep -v lo | grep Link -A1 | grep inet `" ]; then logger -p user.info "An interface is up." if [ -z `pgrep pidgin` ]; then logger -p user.info "Loading Pidgin" pidgin & fi #if [ -z `pgrep ANOTHER_PROGRAM` ]; then # logger -p user.info "Loading ANOTHER_PROGRAM" # ANOTHER_PROGRAM & #fi fi
/etc/init.d/sysklogd start tail -n0 -f /var/log/*/*
chmod 0755 ~/.network-autostart
And you're done!
As explained in the forums this method can also be used to mount network shares only when the network is connected by adding the mounting commands to the .network-autostart file. However, this creates a mounted folder to which the default user does not have access, so it also requires a line to change permissions.
The code will depend on each user's network configuration, but Niel1952 reports that this code works for him:
#! /bin/bash logger -p user.info "Network Autostart Script starting" if [ "`/sbin/ifconfig | grep -v lo | grep Link -A1 | grep inet `" ]; then logger -p user.info "An interface is up." if [ -z `pgrep firefox` ]; then logger -p user.info "Loading Firefox" /opt/firefox/firefox & fi if [ -z `pgrep Videos` ]; then logger -p user.info "Mounting Videos" sudo mount -t cifs -o username=Public,password=******,uid=user,gid=users '//192.168.1.5/Movies' /home/user/My\ Documents/My\ Videos/; sudo chmod 0755 /home/user/My\ Documents/My\ Videos fi #if [ -z `pgrep ANOTHER_PROGRAM` ]; then # logger -p user.info "Loading ANOTHER_PROGRAM" # ANOTHER_PROGRAM & #fi fi
Major credit goes to Jefficus and jimbox51, see this thread. To get gmail notifier, see this thread.