Logo 
Search:

Unix / Linux / Ubuntu Forum

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds

How to automatically run a shell script with sudo in it

  Date: Feb 04    Category: Unix / Linux / Ubuntu    Views: 748
  

I want to create a shell script that can copy a D-Link wireless adapter config
file to directory
/ext/udev/rules.d

Of course to do that it must have root permission. How do I get the script to
run automatically without me having to enter a password?
The shell command I would be using thus far is
sudo cp 10-d_link.rules /etc/udev/rules.d

Share: 

 

3 Answers Found

 
Answer #1    Answered On: Feb 04    

If the script runs at a certain time or interval, you can place it in
root's crontab like this:
sudo crontab -e This will open root's crontab and allow you to edit as
needed.

Here's some info on crontab: https://help.ubuntu.com/community/CronHowto

 
Answer #2    Answered On: Feb 04    

while that doesn't do quite what I want, I did not know about crontab
and cron. Glad to find out about that.

Since the original post I have hooked-up an spare 80G IDE drive and
installed Ubuntu 10.10. When I ran this script:

#!/bin/sh

echo 'install rt2870sta modprobe --ignore-install rt2870sta ; /bin/echo
"07d1 3c16" > /sys/bus/usb/drivers/rt2870/new_id' | sudo tee
/etc/modprobe.d/rt2870sta.conf
sudo modprobe rt2870sta
iwconfig
sudo cp 10-d_link.rules /etc/udev/rules.d/
sudo service udev reload

With this single line in the 10-d_link.rules file
# UDEV-Rule for D-LINK DWA-125N ID 07D1 :3C16 SUBSYSTEM=="usb",
SYSFS{idVendor}=="07d1", SYSFS{idProduct}=="3c16", RUN+="/sbin/modprobe
rt2870sta"

The D-Link DWA-125N came to life blinking it's "HeartLight". Then all I had
to do was pick the wireless connection I wanted to connect to, enter the
SSID and PW and I was online. Going in manually is no big deal, it is just a
mater of a little copy-n-paste but having a script do that mundane setup,
with no fat-fingering, that's the computer's job.

Reading about crontab and cron, cron must stand for chronological, this
stuff resides in the same directory the file 10-d_link.rules gets copied to.
Down there where no man, or woman, should go if they don't know what they
are doing or have someone pointing the way that does know what they are
doing or you could really screw-up you OS to where all the king horses and
all the kings men...

Just for reference, I would still like to know it there is away to run a
script with a sudo line in it that only requires the manual entry of the PW
at initial set-up time.

 
Answer #3    Answered On: Feb 04    

Look at the second post on this thread below. I'm having some trouble
getting all the text there to display correctly on my mobile, but it
looks like the right information from what is not showing garbled...

http://ubuntuforums.org/showthread.php?t=140696

 
Didn't find what you were looking for? Find more on How to automatically run a shell script with sudo in it Or get search suggestion and latest updates.




Tagged: