LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to setup a cron job to ifup eth0? (https://www.linuxquestions.org/questions/linux-general-1/how-to-setup-a-cron-job-to-ifup-eth0-36649/)

cmisip 11-27-2002 04:29 PM

How to setup a cron job to ifup eth0?
 
How do you setup a cron job to setup eth0 IP configuration via dhcp. I can manually do it as root using
#ifup eth0
Determininf IP information for eth0...done.

I need to run a database update program which needs an internet connection. I am trying to run mythfilldatabasecron (if anyone of you is aware of the mythtv program). I added a line to the beginning of my cron file:

#!/bin/bash
/sbin/ifup eth0 ( I added this)
/usr/local/bin/mythfilldatabase (this is the program that needs to run after I have established an network connection to my IP masquerading server)


The second part of the script works but the first part does not and linux complains." Users cannot control this device" when it attempts to execute ifup eth0 in the script. I understand that it needs root privileges. However I am not going to be sitting in the front of the screen to enter a password. Is there a way to make ifup eth0 work on a user cron script ? If not, how can I make sure that there is an active eth0 connection to the IP masqueradeing server before cron executes mythfilldatabase. My IP masquearading server is set up for dial on demand so any network connection to it directed to the internet will open up ppp0.


Thank You Very Much

cmisip 11-27-2002 04:32 PM

an addendum to the above.

I need to ifup eth0 prior to mythfilldatabase because eth0 goes down after a specified lease time. I have this PC running all the time (It is setup as a Tivo Like personal video recorder in Linux).

mdh 11-27-2002 05:24 PM

A couple of options
1: put it in roots crontab
2: configure sudo to allow the user running the script to perform the ifup, then just change the command to sudo ifup eth0

cmisip 11-28-2002 07:33 PM

Thanks. I was able to set up a root cron job that does ifup eth0. It works now. I was wondering if you can tell me how to setup a user with sudo so the user can copy a modified XF86Config-4. I have 2 XF86Config-4 files. One for TV output. The other for Monitor output. I have a script that allows a user to copy either of these XF86config versions over XF86Config-4 but it does so by giving the user all the root privileges ( well I am the user and I am the root also anyway). I did this by editing /etc/sudoers and inserting username ALL=(ALL) ALL under the entry for root in the section User privilege specification. I want to do it properly so that I dont destroy anything accidentally logged as user.

Thanks

mdh 11-28-2002 08:35 PM

Okay, since you already have the script, make it owned by root.
You'll have to setup a command alias for your script and assign the user(s) into a group which is allowed to sudo it

something like
-------------------------------------------------------------------
User_Alias XMODUSERS=user_1,user_2 .... user_n

...

Cmnd_Alias XCONFSCRIPT=/full/path/to/your/script

...

XMODUSERS ALL = NOPASSWD: XCONFSCRIPT
--------------------------------------------------------------------
would do the job (rename the aliases as you see fit.
Effectively any user in group XMODUSERS can, on all systems, execute the command pointed to by XCONFSCRIPT as root without suplying a password


All times are GMT -5. The time now is 02:26 PM.