• Home
  • About Me
  • Welcome to Short Linux hints
Short hints about Linux


  • Tags

    hacking Linux linux cpanel courier maildir mailbox exim security viruses worms
  • Blogroll

    • Geany
    • Handy one-liners for sed
    • Linux By Example
    • Penguin Tutor

Apr 27

Run a command depending on what your IP address is

Linux Add comments

My simple goal is to check what my IP is and run a command correspondingly. My reason is that my laptop's IP is always assigned by DHCP and when I am at home it is always 192.168.0.5. Assume I want to update my Ubuntu regularly but only when I am at home.

To automate the above task I would add the following to /etc/rc.local:

ip a |grep 192.168.0.15 && apt-get update; apt-get upgrade -y

This means that the command (apt-get update; apt-get upgrade -y) will be run only if the previous command is successful. You could grep not only for an IP, but for a whole network or any relative hint.

Comments are closed.

Powered by WordPress .::. Designed by SiteGround Web Hosting

cssandhtml