Results 1 to 4 of 4

Thread: edit text file via a shell or perl script

  1. #1
    Join Date
    May 2008
    Beans
    34
    Distro
    Ubuntu 8.04 Hardy Heron

    edit text file via a shell or perl script

    How can I do this?

    I want to edit /etc/resolv.conf to change it from
    Code:
    nameserver 228.23.501.19
    to
    Code:
    nameserver 75.199.286.4
    . I have to do so every so often (when I'm at home) and want to save myself editing it manually by $sudo nano /etc/resolv.conf.

    Is there a way to do this?

    Thanks.
    Last edited by instantkarma; August 26th, 2009 at 08:24 PM.

  2. #2
    Join Date
    Apr 2009
    Location
    Mumbai (India)
    Beans
    119
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: edit text file via a shell or perl script

    Quote Originally Posted by instantkarma View Post
    How can I do this?

    I want to edit /etc/resolv.conf to change it from
    Code:
    nameserver 212.33.511.29
    to
    Code:
    nameserver 62.219.186.7
    . I have to do so every so often (when I'm at home) and want to save myself editing it manually by $sudo nano /etc/resolv.conf.

    Is there a way to do this?

    Thanks.
    Hi,

    You can try a simple shell script.

    Code:
    #!/bin/sh
    
    echo "nameserver 62.219.186.7" > /etc/resolv.conf ;
    save the script say nameserver.sh make it executable

    Code:
    $ chmod +x nameserver.sh
    you can run it after boot from terminal or you can add it to runlevel so that it updates resolv.conf when system boots up

    This link might help you in running script during boot

    Good luck

  3. #3
    Join Date
    Jun 2008
    Location
    California
    Beans
    2,271
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: edit text file via a shell or perl script

    The following command--which can be placed in a shell script--will do what you want:

    Code:
    sudo sed -i 's/212.33.511.29/62.219.186.7/' /etc/resolv.conf
    Last edited by kaibob; May 17th, 2009 at 12:28 AM.

  4. #4
    Join Date
    May 2008
    Beans
    34
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: edit text file via a shell or perl script

    Quote Originally Posted by zeex View Post
    Hi,

    You can try a simple shell script.

    Code:
    #!/bin/sh
    
    echo "nameserver 62.219.186.7" > /etc/resolv.conf ;
    save the script say nameserver.sh make it executable

    Code:
    $ chmod +x nameserver.sh
    you can run it after boot from terminal or you can add it to runlevel so that it updates resolv.conf when system boots up

    This link might help you in running script during boot

    Good luck
    Works like a charm. Thanks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •