Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 05-26-2009, 03:49 AM   #1
LQ Newbie
Registered: May 2009
Distribution: Kubuntu 9.04
Posts: 10

Rep: Reputation: 0
how to run script after internet connection


I would like to mount my afs account at the university on my home laptop automatically. The problem is that my uni won't allow afs access if I use ssh public/private keypair authentication. That means there is no way around entering the password for my account when I want to mount the remote afs filesystem. (That seems to exclude doing it with autofs+sshfs.)

As a workaround, I've created a script using expect, that enters my password for me. It looks something like:
spawn kinit -A -f login@HOST
expect "login@HOST's Password:"
send "password\r"
expect eof
(yes, I'm aware storing my password in a script like this isn't very safe )
If I run this script myself from shell, it works as it should: I get a kerberos token and I can ssh to my uni account, or use sshfs to mount my afs account locally, without having to enter my password again.

My question now is, how can I make this script run automatically once I've established an internet connection? I use wifi at home, so generally it takes until about a minute after booting until my connection is established. This would exclude running the above script at startup?

I read somewhere that I could put the script at /etc/dhcp3/dhclient-exit-hooks.d/ to have it run automatically once an ip address has been assigned, but that doesn't seem to work (I boot, connect to the internet, but no token). Is there a log somewhere I could check to see if the script runs/generates errors?

I'm really new to all this, so I don't really have a clue of how these things fit together. All information/hints/workarounds you can give me will be highly appreciated!

Last edited by OkoSanto; 05-29-2009 at 08:23 AM.
Old 05-26-2009, 09:06 PM   #2
Senior Member
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
I don't know what the "/etc/dhcp3/dhclient-exit-hooks.d/" directory does so I can't help ya out there. To test it out, write a bash script that writes out a file to /tmp/test.log (or whatever you want to name it) and place it in that directory. Restart your laptop and check if the file exists or not.

You said it takes about 1 minute to grab an IP. Since I'm not fluent in expect, I would write a simple wrapper script in bash and place it in your startup scripts. Something like:


sleep 80 #sleeps for a minute and 20 seconds
expect /path/to/your/expect_script
Old 05-28-2009, 03:21 AM   #3
LQ Newbie
Registered: May 2009
Distribution: Kubuntu 9.04
Posts: 10

Original Poster
Rep: Reputation: 0

Ok, I've figured it out! The first issue is that I'm using Networkmanager to manage my wifi connections. With Networkmanager, the scripts in /etc/dhcp3/dhclient-exit-hooks.d/ are no longer run.

Instead, the Networkmanager daemon runs scripts at /etc/Networkmanager/dispatcher.d/ . Networkmanager passes the variables INTERFACE and ACTION to the script, and you can test for ACTION == 'pre-up' 'up' 'down' 'post-down' to perform different tasks depending on the state of your connection.

Then I had some more trouble to get the syntax correct (your hint of writing a test.log file to see wether the script was actually run, helped to track down the problems, so thanks a lot!)

By calling the expect script above from a bash script in .../dispatcher.d/ my root gets a kerberos token, and I can then automount my afs folder using autofs and sshfs. Which is exactly what I was looking for!

Strange I couldn't find this dispatcher rightaway when googling for "run script after internet connection" etc...


expect, kerberos, network manager, script, scripts, sshfs

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run virtual Machine and Internet connection sharing on Fed8 Linuxllent Fedora 6 02-12-2008 03:27 AM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM
How to run script on connection to given IP? logularjason Linux - Networking 0 09-19-2004 06:49 AM
Run without internet connection scotko Linux - Newbie 10 03-17-2004 10:39 PM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:53 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration