Find the answer to your Linux question:
Results 1 to 7 of 7
I'm new to Linux as of a few days ago, and I only need/use it to run a single program for hosting purposes. I've been trying to set up a ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    4

    terminal script?

    I'm new to Linux as of a few days ago, and I only need/use it to run a single program for hosting purposes. I've been trying to set up a launcher for the program with little success. I did a bit of research on how to code scripts, and I really can't get them to work for me. At all. I'm not even sure how to get 'echo' outputs to work.

    When I open a terminal, there are only two commands I need to type to run the program:

    cd Desktop/byond/bin
    DreamDaemon Test/Test.dmb 1000

    So here's what I would like:

    1) Instructions on how to make a launcher or script to execute those two simple commands. (The closest I could get with a launcher "application in terminal" was to get the terminal to flash on the screen and close.)

    2) Not quite as important, but if easy to do: a script to check if the server is still up and running, and if not, to restart it.

    Any help at all would be appreciated. Thanks!

  2. #2
    Linux Newbie
    Join Date
    Jan 2008
    Location
    UK
    Posts
    211
    Try this in a text editor.

    #!/bin/bash
    echo "first echo"
    string1="second echo"
    echo $string1
    echo "Enter a string"
    read $string2 #enter a string greeting here
    echo $string2
    exec ps

    save as test1.sh
    then do this in a terminal

    chmod a+x test1.sh

    to make it executable

    then ./test1.sh

    and see what it does.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    4
    Awesome Thanks for the example
    Using your example + a reference guide, I've figured out how to delete, copy, and move files.
    as well as run my program of interest.

    I do have one other question, though:

    How can I determine if the program is running using an "if" statement? something like "if [program is running] then..."
    I'm guessing I need to use 'top'?

    "if [ DreamDaemon in top ]" ? something like that would be ideal
    But it just tells me "Permission denied"

  4. #4
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by Random_Bob View Post
    Awesome Thanks for the example
    Using your example + a reference guide, I've figured out how to delete, copy, and move files.
    as well as run my program of interest.

    I do have one other question, though:

    How can I determine if the program is running using an "if" statement? something like "if [program is running] then..."
    I'm guessing I need to use 'top'?

    "if [ DreamDaemon in top ]" ? something like that would be ideal
    But it just tells me "Permission denied"
    You can try something like:

    if [ -n "$(ps -A | grep progname)" ]
    then
    echo yes
    else
    echo no
    fi
    Or this alternative form that some people hate:

    [ -n "$(ps -A | grep progname)" ] && echo yes || echo no

  5. #5
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Ft. Polk, LA
    Posts
    796
    I reccomend you to look at the Advanced Bash Scripting Guide, it is a very useful and informative reference for this kind of stuff.

  6. #6
    Just Joined!
    Join Date
    Feb 2008
    Posts
    4
    Quote Originally Posted by i92guboj View Post
    You can try something like:

    if [ -n "$(ps -A | grep progname)" ]
    then
    echo yes
    else
    echo no
    fi
    if [ -n $(ps -A | grep DreamDaemon) ]
    works, but only if I remove the quotations
    but once the game is up and running, it says I have too many arguments
    I'm not sure why, since it works properly if I do this:
    echo $(ps -A | grep DreamDaemon)

    any ideas?

    Thanks for the link Valan.
    Unfortunately I'm having a really hard time finding what I need, though.
    So far I've been looking up individual commands in various reference guides and testing things via trial + error.

  7. #7
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by Random_Bob View Post
    if [ -n $(ps -A | grep DreamDaemon) ]
    works, but only if I remove the quotations
    but once the game is up and running, it says I have too many arguments
    I'm not sure why, since it works properly if I do this:
    echo $(ps -A | grep DreamDaemon)

    any ideas?

    Thanks for the link Valan.
    Unfortunately I'm having a really hard time finding what I need, though.
    So far I've been looking up individual commands in various reference guides and testing things via trial + error.
    It needs the quotes. -n handles only one argugment. If you don't quote it, the string is interpreted as many strings separated with spaces.

    99% of the times, you definitely want to quote the strings in bash if you know that they might hold spaces.

Posting Permissions

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