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.

Share:
6,973

Related videos on Youtube

rofls
Author by

rofls

Updated on September 18, 2022

Comments

  • rofls
    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
      Matt Malesky almost 12 years
      Can 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.
    • Rinzwind
      Rinzwind almost 12 years
      Make sure you types the password correctly for your wireless ;)
    • us3r
      us3r almost 12 years
      rc.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
      rofls almost 12 years
      a) 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
      rofls almost 12 years
      Will do, ~5 minutes.
    • rofls
      rofls almost 12 years
      They 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
      Mahesh almost 12 years
      Can 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
      Mahesh almost 12 years
      and kindly edit your question with the requested info. If it is long, you may use <paste.ubuntu.com> and post the link here
  • Mahesh
    Mahesh almost 12 years
    Welcome 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.