3

Still new with linux and running ubuntu 12.10

I have a wireless stick (ae2500) which has known issues that has been partially solved using ndiswrapper. However, to use it I must run the same scripts every time I reboot, effectively uninstalling and reinstalling the driver. I made a .sh file to run every time to make it easy, but I must do the sudo login everytime.

There are three solutions I am looking for and although not all are necessary to solve this particular problem, I would still like to know them all for learning purposes.

  1. run scripts or file.sh on boot (as well as other programs)
  2. run scripts or file.sh automatically with root privileges
  3. make the install permanent so as not to have to go through the process every time.

Any additional information that can help me regarding this that I did not think to ask (including streamlining my commands), or general knowledge, would be greatly appreciated. Following are the contents of the file. I pretty much just made it as I would have entered it.

cd ~/ndiswrapper-1.58rc1

sudo modprobe -rf ndiswrapper
sudo rm /etc/modprobe.d/ndiswrapper.conf
sudo rm -r /etc/ndiswrapper/*
sudo depmod -a

sudo make uninstall
sudo make
sudo make install
sudo ndiswrapper -i bcmwlhigh5.inf
ndiswrapper -l
sudo modprobe ndiswrapper
  • Have you tried executing the file manually? – Magpie Jan 19 '13 at 22:08
  • 2
    I do, I want to find a way to automate it. – Graymayre Jan 19 '13 at 22:18
  • Do you run that code in the terminal and need help turning it into a shell script or have you already a script? If the latter see my answer, if not I will try to extend it to help you with your script. – Magpie Jan 20 '13 at 1:44
4

To get a file to execute at start up you essentially want to put the .desktop in /etc/xdg/autostart/

Here is how to set up a .desktop for your file from the command line:

sudo mv file.sh /usr/bin

This moves the shell file path to /usr/bin.

Then go to

/usr/share/applications

Nextyou want to create a .desktop file so you type

sudo -H gedit file.desktop & 

The & means you can still use the terminal but leave the file open. Handy if you have a goldfish memory like I do.

In gedit write:

[Desktop Entry]
Name=myfileName
Exec=/usr/bin/file.sh
Type=Application
Terminal=false

You can close it now if you like. You can jazz it up with an icon by adding the line icon=path/to/icon too if that takes your fancy.

Now to get this file to to run on start up you need to save a copy of it into

/etc/xdg/autostart/

That should work provided the script (myfile.sh) works already, that is.

3

You can try putting your file.sh in /etc/init.d/ and use update-rc.d

update-rc.d file.sh defaults
  • try using: sudo update-rc.d ae2500 defaults – Allfo Jan 19 '13 at 22:30
  • alright, done. this will run the scripts the same way? – Graymayre Jan 19 '13 at 22:32
  • did a reboot and no luck, had to manually run it again – Graymayre Jan 19 '13 at 22:37
  • 1
    When you moved your script file it will execute cd ~/ndiswrapper-1.58 which is now not found. Try moving ndiswrapper-1.58 directory to /etc/init.d/ – Allfo Jan 19 '13 at 22:50
  • so ~ will default to that directory? – Graymayre Jan 19 '13 at 23:03
1

To run it on login (I am on 12.04, so this could be slightly different), simply click on the menu in the far top right (with the shutdown options) and click on Startup Applications...

Then click on Add, give it a name and description and browse to the location of the bash script. log out, then back on and it should work.

If you are doing it this way, I would suggest changing sudo to gksudo in your script so that it will then ask for sudo privileges in a nice GUI, rather than just sitting on the terminal asking for it.

1

I have an alternative suggestion to the other answers: use crontab

as root run crontab and add a job like so

@reboot /path/to/your/script

http://en.wikipedia.org/wiki/Cron#Predefined_scheduling_definitions

This is how I would tackle this problem. I am not prepared to say it is better or worse than other answers and would welcome commentary.

0

[This is a combination of magpie's answer and my own experience.]

To get a .sh script (or any other script) to run at boot you want to;

  1. Put your script in a easy accessible place (e.g. your desktop).
  2. Make sure that if you right click the script and go to properties, in the 'Permissions' tab it says at 'Execute'; 'Anyone'.
  3. Open leafpad or any other text editor and type:

    [Desktop Entry]
    Name=yourScriptName
    Exec=/usr/bin/yourScript.sh
    Type=Application
    Terminal=false
    
  4. Hit Ctrl + S and as name fill in "scriptName.desktop", and save it on your desktop.
  5. Open the terminal with Ctrl + Alt + T.
  6. Type:

    cd ~/Desktop
    

    The ~ means home, it should now say something like:

    userName@computerName:~/Desktop$
    
  7. Then:

    sudo mv yourScript.sh /usr/bin
    

(it is usually recommended to put it in /usr/local/bin so that it can be executed by directly the command yourScript.sh instead of "/path/to/script").

    sudo cp scriptName.desktop /usr/share/applications

    sudo mv scritptName.desktop /etc/xdg/autostart

That's it!

I'm on lubuntu 17.04 and it works great for me,
I hope this was a useful and clear explanation :).

Wessel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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