Find the answer to your Linux question:
Results 1 to 5 of 5
Hello, i want to run these 3 commands on linux rhel boot, please how to start after boot? 1. ssh -f -N -D 0.0.0.0:1080 localhost 2. iptables -A INPUT --src ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User postcd's Avatar
    Join Date
    Apr 2011
    Posts
    348

    Run commands on each boot


    Hello, i want to run these 3 commands on linux rhel boot, please how to start after boot?

    1. ssh -f -N -D 0.0.0.0:1080 localhost
    2. iptables -A INPUT --src 1.2.3.4 -p tcp --dport 1080 -j ACCEPT
    3. iptables -A INPUT -p tcp --dport 1080 -j REJECT

    these should ensure the server will serve as a proxy at port 1080 for mentioned IP only

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,273
    Most distros have a startup script called rc.local, where you put this kind of thing. You'll find it in the /etc tree, usually in /etc/rc.d with the other startup scripts.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  3. #3
    Linux User postcd's Avatar
    Join Date
    Apr 2011
    Posts
    348
    Quote Originally Posted by hazel View Post
    Most distros have a startup script called rc.local, where you put this kind of thing. You'll find it in the /etc tree, usually in /etc/rc.d with the other startup scripts.
    It did not worked, adding my mentioned commands into mentioned rc.local or any other rc/init directories did not launched the commands. The first command asks root password, can i automatically input it? how? thx

    i inputed it by installing sshpass (yum install sshpass) and command looks like:

    pass=mypassword
    sshpass -p "$pass" ssh -f -N -D 0.0.0.0:1080 localhost

    i added commands in a new .sh file with chmod +x permissions and call this .sh file from /etc/rc.d/rc.local (sh /path/to/file.sh) that worked.
    Last edited by postcd; 01-25-2014 at 11:03 AM.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,648
    Here's a pretty good explanation of the services execution process at boot. An introduction to services, runlevels, and rc.d scripts | Linux.com

    Note it differs by distro - and you haven't indicated yours yet. You get different services at different run levels.

  6. #5
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    949
    Have you tried just putting those command in the rc.local file and see if they execute. You're running a shell within a shell that's what concerns me.

Posting Permissions

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