Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I often mount a remote drive using sshfs. I would love to have this mount automatically. However, if I mount it in my .bashrc or startup scripts, the mount often fails because my wireless internet connection has not yet been made.

Does anybody know of an easy way to execute a bash scrip every time the connection is made, or to auto-mount an sshfs drive?

share|improve this question

2 Answers 2

up vote 29 down vote accepted

Add your script to /etc/network/if-up.d/. Name your script without a '.sh' extension.

Also after adding script run chmod +x /etc/network/if-up.d/yourscriptname to give necessary permission.

Make sure the network interface (e.g. wlan0 or eth0) that should trigger your script when turned on is mentioned in the file /etc/network/interfaces.

share|improve this answer
6  
inside scripts in /etc/network/*.d/ you can use the variable $IFACE to know which interface is getting a connection so you can skip the procedure if it is the wired connection for example. –  Carlos Campderrós Feb 20 '13 at 9:22
    
Is there a way to specify which specific network you want to do this for? when it's my home network I want to do the script but when I'ts a network out and about I might not want to... –  Joshua Robison Apr 28 '13 at 9:21
    
this actually doesn't seem to work at all. I know my scripts work because I can run them using ./ in the terminal and they work but when I toggle off and on the connection, the scripts are not called at all. Is there anything that I have to do to reference them in someway? dropping a script in if-up.d seems to be lacking a step?!?! –  Joshua Robison Apr 28 '13 at 10:30
    
check whether they hace correct permissions please. –  dedunumax Jul 2 '13 at 5:47
1  
Please add what exactly should go into interfaces when it is not there. Is it auto wlan0 and iface wlan0 inet dhcp or sth else? –  Cookie Mar 25 at 15:40

Ubuntu 12.04

  • Install Cuttlefish Install Cuttlefish : A simple tool, which realises reflexes on your computer by executing actions when specific events are triggered.
  • Open Cuttlefish and click on New.

Step-1

  • Give it a name, and change Activated by stimulus option to ON.
  • Click on Stimulus, select the category Network and type Connect to WLAN. Click OK.

Step 2

  • You can also select the SSID of wireless network and you have an option of whether or not to check this on startup.

Step 3

  • Now you will have to specify a reaction. Go to Reaction tab, and click add. Select Applications from the category and Start Application(in advanced mode) from type.

Step 4

  • Now specify the script which you want to run in executable option. You can even pass parameters to the script.

Step-5

  • And that's it! Also make sure that you add Cuttlefish in startup applications. Go to Edit > Preferences and enable the autostart option.

Step-6

share|improve this answer
1  
cuttlefish is completely broken and hasn't seen an update for sometime. I wish it could get more development because we need something like Android's Tasker app for Linux. Nobody wants to mess with etc/network/interfaces and if-up folders and scripts. Just give me something I can click or toggle on and off. –  Joshua Robison Jan 19 at 4:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.