Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Need help fixing this .sh file, only half works.

    Ok, firt my apologies if this is in the wrong spot. I seriosuly didn't know where to stick this. In any event, I have a game server I'd like to have started on server reboot and I got the baic idea of what I need to do using an @reboot cronjob but I'm having an issue with the .sh file involved.

    ---

    Below is the contents of the .sh file involved, I don't have the cron set up yet to get it goin after server restart. I'm currently testing it running the following command.

    sh minecraft_autostart.sh

    Code:
    #!/bin/sh
    
    # McMyAdmin / Minecraft Server Autostart Script
    # Called via Cron (@reboot /home/user/minecraft_autostart.sh)
    screen -S minecraft
    screen -X
    cd ./public_html/mcmyadmin/
    mono McMyAdmin.exe -nostart
    Ok, so here's what's wrong... the screen loads or whatever you wana call it but then that's it. Nothing, so I close the screen out and then I see the other stuff run (the mono stuff).

    Well, someone suggested I add a screen -X, well I tried that and still nothing. If your still with me and sort of get what I'm trying to achieve here then I would really appreciate the help. It was also suggested I not CD the path but instead use a full path, didnt quite follow them on that one but the below quote is the last thing I got from my host before coming here as they sort of hinted towards.

    Hello,

    If you run the script manually it will use your tty. If you want the next two commands sent to the screen you will have to use screen -X option. You should also just use the full path to eliminate the need for a cd command. We really can't tell you much more as you are now running into scripting issues. Please consult the appropriate forums for assistance.
    Last edited by MoreBloodWine; 12-22-2011 at 12:01 AM.

  • #2
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Anyone ?

  • #3
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Assuming cron is actually calling that script (try echo test >/home/login/test), typically cron doesn't have the same path as your user account, so everything will need the full path specified.

    To find the full path to an executable, say screen, run "which screen"
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #4
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Lamped View Post
    Assuming cron is actually calling that script (try echo test >/home/login/test), typically cron doesn't have the same path as your user account, so everything will need the full path specified.

    To find the full path to an executable, say screen, run "which screen"
    Full path thing figured out, someone told me to just get rid of the cd line and relace it with /home/me/whatever/

    Still need hel with the "other" issue.

  • #5
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    I know what mono and screen are, but I don't use either. I don't know if mono will direct it's output through the "normal stdout", or if mono will catch stderr...

    1. Look into mono/screen compatibility.

    2. Try putting 2>&1 at the end of the mono line - that will copy all errors to the normal output.

    I understand why you're using screen, but if it's causing an issue, why not look at some logging option, or redirect output to a file (you can then tail -f file later)
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #6
    Regular Coder
    Join Date
    Nov 2010
    Posts
    204
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Lamped View Post
    I know what mono and screen are, but I don't use either. I don't know if mono will direct it's output through the "normal stdout", or if mono will catch stderr...

    1. Look into mono/screen compatibility.

    2. Try putting 2>&1 at the end of the mono line - that will copy all errors to the normal output.

    I understand why you're using screen, but if it's causing an issue, why not look at some logging option, or redirect output to a file (you can then tail -f file later)
    I'm also talking to my host about this but it should technically be working, at lease through the screen -X line where it should be attaching to the recently opened screen. Also, logging option ?

    Don't follow ya, if there was another way to do this I would but I need screen so I can manipulate the program after it's been opened.

  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    88
    Thanks
    4
    Thanked 26 Times in 26 Posts
    Thinking back - and it's been a while so forgive me if I'm completely wrong - but screen is a terminal command for effectively multiplexing windowed shells/terminals.

    From memory, running a program from cron means there is no display to output to as such, so I wonder if screen would run at all? Or, if it's even needed in the context of the script as it would just be a task running.

    Like I say, I may be way off - but something rings a bell here.

  • #8
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Screen provides a virtual tty that can be connected/disconnected to an actual tty as needed. It shouldn't require an actual tty if started disconnected.

    As you've mentioned you require interaction with it, obviously screen is the way to go. I have no further suggestions, other than to try the channel for your Linux distribution on Freenode IRC.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #9
    New Coder
    Join Date
    Nov 2011
    Posts
    88
    Thanks
    4
    Thanked 26 Times in 26 Posts
    Quote Originally Posted by Lamped View Post
    Screen provides a virtual tty that can be connected/disconnected to an actual tty as needed. It shouldn't require an actual tty if started disconnected.
    But as it is being started from a CRON job, with no tty of any kind (virtual or otherwise) then you can ask the current TTY to open a screen session - it does not exist and you have nothing to disconnect it from. So to make it work you'd have to create a TTY of some kind to spawn a screen from. This seems to cover it, but I've not tested it myself:

    http://www.linuxquestions.org/questi...on-job-349153/


  •  

    Posting Permissions

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