Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: run a sh file on tty1-7 while using GUI on tty8

  1. #1
    Join Date
    Apr 2013
    Beans
    8

    run a sh file on tty1-7 while using GUI on tty8

    Firstly, if this post is in the wrong topic, feel free to move. I found "General Help" the most relevant.

    I currently have a minecraft server running normally on the GUI server tty8 via a terminal emulator. I would like to be able to move the server to tty1-7 so that I can do whatever using the normal GUI tty.

    The server uses Ubuntu 12.10 with the specs being:
    -Intel Core i7-2630QM Processor 6M Cache, up to 2.90 GHz
    -8GB DDR3 Ram
    -Cat6 Gigabit Ethernet
    -750GB 5200RPM WD Blue SATA
    -Intel HD3000/Nvidia 520MX
    I know how to log in to a tty and start a server but I would like to do the following:
    I want the computer to start up normally and default to the tty8 GUI logon screen while on the server tty I want:
    -auto login to server user (username is "mcserver")
    -run this shell file:
    Code:
    #!/bin/sh
    Pause()
    {
     OLDCONFIG=`stty -g`
     stty -icanon -echo min 1 time 0
     dd count=1 2>/dev/null
     stty $OLDCONFIG
    }
     
    echo "Hit a key to start the server..."
    Pause
    echo "Server starting....."
    
    sh ~/mcs/craftbukkit.sh
    Thanks for any help, it is appreciated :>
    Last edited by ada101; April 21st, 2013 at 04:50 AM. Reason: To mark the thread as solved :)

  2. #2
    Join Date
    Apr 2006
    Location
    Ubuntuland
    Beans
    2,124
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: run a sh file on tty1-7 while using GUI on tty8

    run it from rc.local (without the pause).
    Otherwise, you'll just have to open a console manually (Ctrl-Alt-F1) and do it yourself.
    24 beers in a case, 24 hours in a day. Coincidence? I think not!

    Trusty Tahr 64 bit, AMD Phenom II 955 Quad Core 3.2GHz, GeForce 9600 GT
    16G PC2-6400 RAM, 128 GB SSD, Twin 1TB SATA 7200 RPM RAID0

  3. #3
    Join Date
    Apr 2013
    Beans
    8

    What is rc.local?

    rc.local? I have found it in /etc/. Do I just paste the script in there? How will rc.local know to log in as mcserver and how will it know which tty to load up on?
    Currently, the rc.local looks like this:
    Code:
    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    exit 0
    Thanks

  4. #4
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    9,861
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: What is rc.local?

    Looks like the actual command to start the server is "sh ~/mcs/craftbukkit.sh". Just put that above the "exit 0" line and reboot.
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  5. #5
    Join Date
    Apr 2006
    Location
    Ubuntuland
    Beans
    2,124
    Distro
    Ubuntu 13.10 Saucy Salamander

    Question Re: What is rc.local?

    Quote Originally Posted by ada101 View Post
    rc.local? I have found it in /etc/. Do I just paste the script in there? How will rc.local know to log in as mcserver and how will it know which tty to load up on?
    Currently, the rc.local looks like this:
    Code:
    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    exit 0
    Thanks
    Servers normally run as root. Why do want it to run as a specific user?
    24 beers in a case, 24 hours in a day. Coincidence? I think not!

    Trusty Tahr 64 bit, AMD Phenom II 955 Quad Core 3.2GHz, GeForce 9600 GT
    16G PC2-6400 RAM, 128 GB SSD, Twin 1TB SATA 7200 RPM RAID0

  6. #6
    Join Date
    May 2010
    Location
    uk
    Beans
    8,102
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: run a sh file on tty1-7 while using GUI on tty8

    Hi

    I would attempt to do this a different way than suggested so far. For choice i'll elucidate.

    For auto login, install mingetty

    Code:
    sudo apt-get install mingetty
    Which ever console you want to auto login edit the ttyX.conf file.

    In his example

    Code:
    sudo nano /etc/init/tty1.conf
    Change the last line from

    Code:
    exec /sbin/getty 38400 tty1
    to read


    Code:
    exec /sbin/mingetty --autologin USERNAME tty1
    Change USERNAME to the correct user.

    There is also the -f switch for /bin/login but i have not played with that.

    You can then run a script. Place it in

    Code:
    .bash_profile
    You may have to create it. This script get sourced for a bash login shell.

    in the script you can check the current tty

    Code:
    TTY=$(tty);
    
    if [[ "$TTY" == "/dev/tty1" ]];
    then
    
      run script.
    
    fi
    The script will run on the correct tty under the correct users credentials.

    If i understand your post correctly, this is kind of what you want.

    Kind regards
    Last edited by matt_symes; April 21st, 2013 at 04:58 AM.
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

  7. #7
    Join Date
    May 2010
    Location
    uk
    Beans
    8,102
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: What is rc.local?

    Hi

    Quote Originally Posted by Slim Odds View Post
    Servers normally run as root. Why do want it to run as a specific user?
    I have never set up a minecraft server so i'm interested in this question.

    My assumption is security.

    Kind regards
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

  8. #8
    Join Date
    Apr 2013
    Beans
    8

    Re: run a sh file on tty1-7 while using GUI on tty8

    So many replies! Lets get down to it then
    Quote Originally Posted by Slim Odds View Post
    Servers normally run as root. Why do want it to run as a specific user?
    A Minecraft Server running as root? Firstly, its java, and I don't trust Java. Too many exploits. Type "run minecraft server as root" into Google and look at the captions of the results.
    Quote Originally Posted by matt_symes View Post
    Hi

    I would attempt to do this a different way than suggested so far. For choice i'll elucidate.

    For auto login, install mingetty

    Code:
    sudo apt-get install mingetty
    Which ever console you want to auto login edit the ttyX.conf file.

    In his example

    Code:
    sudo nano /etc/init/tty1.conf
    Change the last line from

    Code:
    exec /sbin/getty 38400 tty1
    to read


    Code:
    exec /sbin/mingetty --autologin USERNAME tty1
    Change USERNAME to the correct user.

    There is also the -f switch for /bin/login but i have not played with that.

    You can then run a script. Place it in

    Code:
    .bash_profile
    You may have to create it. This script get sourced for a bash login shell.

    in the script you can check the current tty

    Code:
    TTY=$(tty);
    
    if [[ "$TTY" == "/dev/tty1" ]];
    then
    
      run script.
    
    fi
    The script will run on the correct tty under the correct users credentials.

    If i understand your post correctly, this is kind of what you want.

    Kind regards
    Will try this approach tommorow, sounds promising It is currently 3AM in my time zone, so not now
    Quote Originally Posted by matt_symes View Post
    Hi



    I have never set up a minecraft server so i'm interested in this question.

    My assumption is security.

    Kind regards
    As I said before, Java .
    Quote Originally Posted by SeijiSensei View Post
    Looks like the actual command to start the server is "sh ~/mcs/craftbukkit.sh". Just put that above the "exit 0" line and reboot.
    I don't want the server to start every time I use the PC. If I stick a pause in, I can just leave the tty paused until I want the server on again.
    Last edited by matt_symes; April 21st, 2013 at 04:59 AM.

  9. #9
    Join Date
    Oct 2009
    Location
    Elgin, IL USA
    Beans
    2,709
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: run a sh file on tty1-7 while using GUI on tty8

    There is no need to run a minecraft server as root, since it does not use any low ports (default port 25565) and is safer that way.

    When someone on the Raspberry Pi forum asked how to boot right into a text terminal (tty) program as a specific user, I was not aware of the mingetty --autologin parameter, but I found an autologin ksh script and did a little web page about how to do that in /etc/inittab in place of a regular getty, and then launch the text terminal program from ~/.profile for that user. Raspberry Pi is an ARM computer on a credit card size circuit board (for $35) that boots a Debian wheezy version called Raspbian from SD card, so it is easy to customize an SD card for specific use (Ubuntu is also Debian based). One thing that the autologin script did not set was $TERM, so I had to set TERM=linux in ~/.profile.

    So you may gain some useful information from this, which does not even launch any gui, but boots right into quake3 launched from a tty: http://efflandt.freeshell.org/rpi-web/autotermrun.html
    i5 650 3.2 GHz, 8 GB, nvidia GTX 750 Ti, 32" 1080p | i7-4700MQ, 8 GB, Intel HD 4600/nvidia GTX 765M, 15.6" 1080p | etc.

  10. #10
    Join Date
    Apr 2013
    Beans
    8

    Re: run a sh file on tty1-7 while using GUI on tty8

    matt_symes, I used this method in virtualbox last night, and it worked!!!! Thank you so much everyone for your input, and a big thanks to matt_symes for your method! I now have to install this stuff on my server pc. They both run the same OS, so should both be the same . Here is a screenshot of the server running off of tty1 in virtualbox:

    Will post here if I have any problems installing on the server .

    Quote Originally Posted by matt_symes View Post
    Hi

    I would attempt to do this a different way than suggested so far. For choice i'll elucidate.

    For auto login, install mingetty

    Code:
    sudo apt-get install mingetty
    Which ever console you want to auto login edit the ttyX.conf file.

    In his example

    Code:
    sudo nano /etc/init/tty1.conf
    Change the last line from

    Code:
    exec /sbin/getty 38400 tty1
    to read


    Code:
    exec /sbin/mingetty --autologin USERNAME tty1
    Change USERNAME to the correct user.

    There is also the -f switch for /bin/login but i have not played with that.

    You can then run a script. Place it in

    Code:
    .bash_profile
    You may have to create it. This script get sourced for a bash login shell.

    in the script you can check the current tty

    Code:
    TTY=$(tty);
    
    if [[ "$TTY" == "/dev/tty1" ]];
    then
    
      run script.
    
    fi
    The script will run on the correct tty under the correct users credentials.

    If i understand your post correctly, this is kind of what you want.

    Kind regards
    Last edited by matt_symes; April 21st, 2013 at 05:00 AM.

Page 1 of 2 12 LastLast

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
  •