How can I automate a root command after (not during) startup?
6,973
One workaround would be to use rc.local with a sleep command. Put the following into /etc/rc.local:
(sleep 60; dhclient) &
This will make the command wait for 60 seconds before being executed, which should allow enough time for your machine to finish booting.
Related videos on Youtube
Author by
rofls
Updated on September 18, 2022Comments
-
rofls over 1 year
I'm using Ubuntu 12.04 LTS, but I need to run the following command:
sudo dhclient
after startup to acquire a stable ethernet connection. I am running dhclient during startup already, through the /etc/rc.local file.
Someone please help me run this command after-startup automatically (by removing it's requirement for root, or some other means), or suggest a different way of troubleshooting my ethernet connection.
-
Matt Malesky almost 12 yearsCan you give us the output of the command
ifconfig
after you have rebooted (but before you've runsudo dhclient
), and again after you have runsudo dhclient
? It sounds like you may have an IP address incorrectly configured/not configured for DHCP on your network interface. -
Rinzwind almost 12 yearsMake sure you types the password correctly for your wireless ;)
-
us3r almost 12 yearsrc.local is executing with root permission, so you dont need to use a sudo. Is everything alright in your Network Manager? You can try to remove Network Manager and configure a /etc/network/interfaces
-
rofls almost 12 yearsa) it's wired, see "ethernet" b) rc.local isn't working, I think it's because it's running dhclient before the system is fully booted. That's why I'm trying to run it immediately after boot, or login c) I think something is definitely wrong with my Network Manager, but I don't know how to follow your instructions, could you be more precise?
-
rofls almost 12 yearsWill do, ~5 minutes.
-
rofls almost 12 yearsThey were nearly the same. Only difference was that there are significantly more RX and TX packets after, which I think means I'm getting an IP address, just not looking up websites correctly or something. It will occasionally browse before running dhclient, just not reliably and quickly.
-
Mahesh almost 12 yearsCan you give us the output of the command ifconfig after you have rebooted (but before you've run sudo dhclient), and again after you have run sudo dhclient? It sounds like you may have an IP address incorrectly configured/not configured for DHCP on your network interface. (ps: comment from Matt)
-
Mahesh almost 12 yearsand kindly edit your question with the requested info. If it is long, you may use <paste.ubuntu.com> and post the link here
-
-
Mahesh almost 12 yearsWelcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.