Results 1 to 9 of 9

Thread: How to run a command at startup with screen?

  1. #1
    Join Date
    Nov 2009
    Beans
    110

    How to run a command at startup with screen?

    Hi. I need to run a shell script in a screen session on every reboot. How can I do this ? I tried with "@reboot /path/to/script" in crontab but its not working. I found this http://serverfault.com/questions/233...screen-session but I can't understand it. Can you help me with this ? TYA

  2. #2
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    /etc/rc.local

    You might try launching your script from /etc/rc.local. It is run after all the other SystemV init scripts.

    screen is very powerful and a bit complex. If the complexity is where you are having trouble, then you might look also at tmux. It is a lot simpler and lacks many (most) of the features of screen but it can attach/detach nicely on demand.

  3. #3
    Join Date
    Nov 2009
    Beans
    110

    Re: /etc/rc.local

    Quote Originally Posted by Lars Noodén View Post
    You might try launching your script from /etc/rc.local. It is run after all the other SystemV init scripts.

    screen is very powerful and a bit complex. If the complexity is where you are having trouble, then you might look also at tmux. It is a lot simpler and lacks many (most) of the features of screen but it can attach/detach nicely on demand.
    How would launch it from /etc/rc.local ? Just copy it there?
    Also if I use tmux - how to run the script with tmux on reboot?

  4. #4
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: /etc/rc.local

    Yes, just copy it there, putting it ahead of the line 'exit 0'

    If you use tmux it can go something like this:

    Code:
    /usr/bin/tmux new-session -d '/usr/local/bin/myscript'
    That will start a new session, launch your script, then detach.

  5. #5
    Join Date
    Nov 2009
    Beans
    110

    Re: /etc/rc.local

    Quote Originally Posted by Lars Noodén View Post
    Yes, just copy it there, putting it ahead of the line 'exit 0'

    If you use tmux it can go something like this:

    Code:
    /usr/bin/tmux new-session -d '/usr/local/bin/myscript'
    That will start a new session, launch your script, then detach.
    So i copied this line (with my details) in rc.local. I rebooted and now in the running processes i see "sleep 720" which is part of the shell script. But I dont see the name of the script there. tmux is running. The same thing happened when I used "@reboot script.sh" in cron. So how can i tell if its running correctly ?
    Last edited by Nailox; January 13th, 2012 at 02:15 PM.

  6. #6
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to run a command at startup with screen?

    You can see if tmux is running properly by listing sessions or trying to attach.

    Code:
    # list sessions
    tmux list-sessions
    
    # or attach
    tmux a
    Does your script work if you run it manually?

  7. #7
    Join Date
    Nov 2009
    Beans
    110

    Re: How to run a command at startup with screen?

    Quote Originally Posted by Lars Noodén View Post
    You can see if tmux is running properly by listing sessions or trying to attach.

    Code:
    # list sessions
    tmux list-sessions
    
    # or attach
    tmux a
    Does your script work if you run it manually?
    ok I rebooted and listed sessions - i see one window
    I attached to it and I can see the script running. So that means its all good right ?

  8. #8
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to run a command at startup with screen?

    Yes, congratulations!

  9. #9
    Join Date
    Nov 2009
    Beans
    110

    Re: How to run a command at startup with screen?

    Thanks a lot for the help !

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
  •