Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 25 Oct 2014, 08:21
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Execute script at network connect/disconnect
Moderators: Flash, Ian, JohnMurga
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count_1  
Author Message
Ibidem

Joined: 25 May 2010
Posts: 501
Location: State of Jefferson

PostPosted: Thu 03 Jan 2013, 01:39    Post_subject:  wpa_cli action scripts  

Have you ever wanted to execute something automatically on network connect/disconnect?
If you use wpa_supplicant to connect, you can. This is most useful for properly timing a DHCP request, but there are other uses...
I gave a summary of this here (my second post, near the end of that page), but there are some possible extensions to the idea.
The basic idea is that if wpa_cli isinvoked with -a <action script>, it will execute the script with certain parameters...

Starting script (assumes a working udhcpc):
Code:
#!/bin/sh
#wpa_cli invokes this on network connection/disconnect
#as $0 $IFACE CONNECTED or DISCONNECTED
case $2 in
CONNECTED)
udhcpc -i $1 -h `hostname`
;;
DISCONNECTED)
;;
*)
;;
esac


Of course, this has a slight problem: it may result in multiple udhcpc instances managing the same interface. Usually this works fine, but here's how one could avoid it. I threw in some code to allow deconfiguring an interface.
Code:
#!/bin/sh
PIDFILE=/var/run/udhcpc/${1}.pid
get_lease()(
mkdir -p `dirname $PIDFILE`
kill `cat $PIDFILE`
udhcpc -i $1 -h `hostname` -f -p $PIDFILE
rm -f $PIDFILE
)

case $2 in
CONNECTED)
get_lease $1 &
;;
DISCONNECTED)
kill `cat $PIDFILE`
;;
stop)
kill `cat $PIDFILE`
wpa_cli -i $1 -p /var/run/wpa_supplicant terminate
;;
*)
cat <<EOF >&2
Usage:
wpa_cli -a $0 -B : Use as wpa_cli action script
$0 eth1 CONNECTED : signal network connect/get a DHCP lease
$0 wlan0 DISCONNECTED : signals network disconnect
$0 ra0 stop : Kill wpa_supplicant/ deconfigure interface
EOF
esac
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count_1  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0384s ][ Queries: 11 (0.0035s) ][ GZIP on ]