You are not logged in.

#1 2014-10-30 13:43:41

fennectech
Member
From: /home/fennectech/
Registered: 2014-06-04
Posts: 169

BASH help

okay so i need help writing a bash script to run minecraft server i need a way to loop it    can someone make me a script template that will loop over and over   so i can script my server


[FennecTECH@ArchOS ~]$ cat about_myself
Hello there my name is FennecTECH I am a novice arch user though I am here to learn  I live in central Minnesota where I hangout in the console and make my way into X11. Nice to meet you all! Enjoy my home directory feel free to poke around. There is a solution to every problem, so long as you do not break the laws of physics.
=^_^=
[FennecTECH@ArchOS ~]$

Offline

#2 2014-10-30 13:49:13

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: BASH help

You need to loop what, exactly? Have you looked for any examples on the web? You're surely not the first person to run a Linux-based Minecraft server.

http://minecraft.gamepedia.com/Tutorial … structions
http://mywiki.wooledge.org/BashGuide/Te … and_for.29

Offline

#3 2014-10-30 13:57:17

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: BASH help

Have you read the wiki's Minecraft page?

Offline

#5 2014-10-30 14:23:08

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,560
Website

Re: BASH help

As indicated above, this question needs a lot of clarification.  But to highlight why it's needs clarification, I'll post the answer to the question as it was asked:

#!/bin/bash
while :; do :; done

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2014-10-30 15:04:19

fennectech
Member
From: /home/fennectech/
Registered: 2014-06-04
Posts: 169

Re: BASH help

this is the script im tryting to convert from windows batch to bash script

echo off
:start
java  -jar -Xms2000M -Xmx3000M forge-1.7.10-10.13.0.1180-universal.jar nogui -o true
@echo off
#pause
cls
echo Restarting in 5
ping -n 2 127.0.0.1>nul
cls
echo Restarting in 4
ping -n 2 127.0.0.1>nul
cls
echo Restarting in 3
ping -n 2 127.0.0.1>nul
cls
echo Restarting in 2
ping -n 2 127.0.0.1>nul
cls
echo Restarting in 1
ping -n 2 127.0.0.1>nul
cls
echo Will Now Restart!
ping -n 2 127.0.0.1>nul
goto start

  EDIT
i can easily convert the java and pingsleep into what i need   just dont know how to loop in a multiple line thing

Last edited by fennectech (2014-10-30 16:06:57)


[FennecTECH@ArchOS ~]$ cat about_myself
Hello there my name is FennecTECH I am a novice arch user though I am here to learn  I live in central Minnesota where I hangout in the console and make my way into X11. Nice to meet you all! Enjoy my home directory feel free to poke around. There is a solution to every problem, so long as you do not break the laws of physics.
=^_^=
[FennecTECH@ArchOS ~]$

Offline

#7 2014-10-30 19:58:57

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: BASH help

Something like:

while true ; do
    echo "Starting my server..."
    for ((n=0;n<5;n++)) ; do
        echo Restarting in $n seconds
        sleep 1
    done
done

Offline

#8 2014-10-30 20:17:56

fennectech
Member
From: /home/fennectech/
Registered: 2014-06-04
Posts: 169

Re: BASH help

its doing it backwords   i want to go 
Will now restart in 5 seconds
4 seconds
3 seconds
2 seconds
1 second
WILL NOW RESTART!


but it counts up hmm


[FennecTECH@ArchOS ~]$ cat about_myself
Hello there my name is FennecTECH I am a novice arch user though I am here to learn  I live in central Minnesota where I hangout in the console and make my way into X11. Nice to meet you all! Enjoy my home directory feel free to poke around. There is a solution to every problem, so long as you do not break the laws of physics.
=^_^=
[FennecTECH@ArchOS ~]$

Offline

#9 2014-10-30 20:23:54

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: BASH help

Type this command, and it should work.

man bash

If you insist:

while true ; do
    echo "Starting my server..."
    for ((n=5;n>0;n--)) ; do
        echo Restarting in $n seconds
        sleep 1
    done
done

Offline

#10 2014-10-30 20:24:46

fennectech
Member
From: /home/fennectech/
Registered: 2014-06-04
Posts: 169

Re: BASH help

i played with the numbers to try to reverse it   but it doesnt work

while true ; do
    echo "Starting my server..."
    for ((n=5;n<0;n--)) ; do
        echo Restarting in $n seconds
        sleep 1
    done
done

Last edited by fennectech (2014-10-30 20:25:44)


[FennecTECH@ArchOS ~]$ cat about_myself
Hello there my name is FennecTECH I am a novice arch user though I am here to learn  I live in central Minnesota where I hangout in the console and make my way into X11. Nice to meet you all! Enjoy my home directory feel free to poke around. There is a solution to every problem, so long as you do not break the laws of physics.
=^_^=
[FennecTECH@ArchOS ~]$

Offline

#11 2014-10-30 20:28:38

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: BASH help

Because, you should say n>0 (and not n<0) in the for loop (and you probably don't have typed my first command).

Last edited by olive (2014-10-30 20:29:32)

Offline

#12 2014-10-30 21:10:04

fennectech
Member
From: /home/fennectech/
Registered: 2014-06-04
Posts: 169

Re: BASH help

@olive    do you know of any good video tutorials to bash scripting?


[FennecTECH@ArchOS ~]$ cat about_myself
Hello there my name is FennecTECH I am a novice arch user though I am here to learn  I live in central Minnesota where I hangout in the console and make my way into X11. Nice to meet you all! Enjoy my home directory feel free to poke around. There is a solution to every problem, so long as you do not break the laws of physics.
=^_^=
[FennecTECH@ArchOS ~]$

Offline

#13 2014-10-30 21:18:00

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: BASH help

There are no good video turorials for bash scripting. There is, however, http://mywiki.wooledge.org/


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#14 2014-10-31 04:52:17

efasckenoth
Member
Registered: 2014-10-08
Posts: 3

Re: BASH help

@fennectech: One does not learn how to program by watching video tutorials. The Linux Command Line has a decent introduction to shell scripting. Once you digested this you might consider working through The Advanced Bash Scripting Guide where you will learn everything you ever wanted to know (and lots of things you'd probably rather not know) about bash scripting.

Last edited by efasckenoth (2014-10-31 04:53:10)

Offline

#15 2014-10-31 05:25:13

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: BASH help

Bash Hackers on the ABS wrote:

Has a lot of information that is hard to find, but is outdated and often unsafe. To be avoided until you can filter out the good stuff.

http://wiki.bash-hackers.org/scripting/tutoriallist


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#16 2014-10-31 05:56:39

efasckenoth
Member
Registered: 2014-10-08
Posts: 3

Re: BASH help

Thanks for the pointer, jasonwryan. The ABS definitely shows some age. It deals with lots of corner cases however, which can be helpful when shell scripts don't behave as expected.

Offline

#17 2014-10-31 07:08:37

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: BASH help

I don't know of video tutorial, I never watch them. But the wikipedia page of shell scripting: http://en.wikipedia.org/wiki/Shell_script (Look at the external links section) gives you some reference, some looks good. Once you grasp the basic, the man page of bash is the reference.

Last edited by olive (2014-10-31 07:14:12)

Offline

#18 2014-10-31 08:01:25

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: BASH help

Apart from the general efforts to learn bash, can I ask why you want this on-screen countdown? What purpose does it serve?

The minecraft-server package in the AUR provides a systemd service, would you consider trying that instead?

Offline

#19 2014-10-31 13:06:02

fennectech
Member
From: /home/fennectech/
Registered: 2014-06-04
Posts: 169

Re: BASH help

the onscreen countdown gives me a chance to do a Ctrl +C to abort the server startup squence without causing damage    allowing for easy maintaince
but if i could systemd the server(with forge)  that would be awesome


[FennecTECH@ArchOS ~]$ cat about_myself
Hello there my name is FennecTECH I am a novice arch user though I am here to learn  I live in central Minnesota where I hangout in the console and make my way into X11. Nice to meet you all! Enjoy my home directory feel free to poke around. There is a solution to every problem, so long as you do not break the laws of physics.
=^_^=
[FennecTECH@ArchOS ~]$

Offline

Board footer

Powered by FluxBB