two questions about incorporating fortune and java uptime into screen for a minecraft server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting two questions about incorporating fortune and java uptime into screen for a minecraft server
# 1  
Old 08-02-2012
two questions about incorporating fortune and java uptime into screen for a minecraft server

existing code

Code:
#!/bin/bash
SRC_DIR=/home/brian/mc/
DEST_DIR=/home/brian/mcbak/
SCREEN_SESSION=minecraft
BACKUP_LOG=/home/brian/mcbaklog
CHKBAK=$(rdiff-backup -v3 --verify ~/mcbak)
BAKSZ=$(du -sh ~/mcbak|awk 'FNR == 1 {print $1}')
WLDSZ=$(du -sh ~/mc/world/|awk 'FNR == 1 {print $1}')
UPTIME_DAYS=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 / 86400)
UPTIME_HOURS=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 % 86400 / 3600)
UPTIME_MINUTES=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 % 86400 % 3600 / 60)
FORT=$(/usr/games/fortune)

UPTIME=$(uptime | sed 's/.*up \([^,]*\), .*/\1/')


if [ : ]; then
        START_TIME=$(date +%s)
        screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say Begin mindray transmission:\r"`"
        screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say Current Server Uptime:$ UPTIME_DAYS days, $UPTIME_HOURS hours, $UPTIME_MINUTES minutes. Current World Size: ${WLDSZ}. \r"`"
		screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say Backup starting...\r"`"
        rdiff-backup -v5 --print-statistics ${SRC_DIR} ${DEST_DIR} >> ${BACKUP_LOG}
        END_TIME=$(date +%s)
        DIFF=$(( ${END_TIME} - ${START_TIME} ))
        screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say Backup finished, and took ${DIFF} seconds to complete.\r"`"    
    
        echo "`date`: rdiff-backup finished, took ${DIFF} seconds to complete " >> ${BACKUP_LOG}
		
        exit 0
fi


what I would like to do is two things.
first would be to add java uptime to print the same as the server uptime.

So far I have

Code:
brian@pufffy:~$ ps -C java|awk 'FNR == 2 {print $3}'

This returns
[QUOTE]
00:14:43



how can I print this out with simular output to

Code:
UPTIME_DAYS=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 / 86400)
UPTIME_HOURS=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 % 86400 / 3600)
UPTIME_MINUTES=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 % 86400 % 3600 / 60)
====
        screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say Current Server Uptime:$ UPTIME_DAYS days, $UPTIME_HOURS hours, $UPTIME_MINUTES minutes. Current World Size: ${WLDSZ}. \r"`"


This returns

Code:
Current Server Uptime is 0 days 0 hours 0 minutes


and I would like to print java uptime the same way.


About fortune
I would love to print the output to a screen session in the same format as the above code. I have no idea how to do this or if it possible. The problem is the screen session is running a minecraft server and the syntax is "Say insert message here: carriage return" and the text input is limited to about 110 char so lets say 100 to be safe with 4 on the front for "say ". Also it hates tabs indentation and most formatting and will not return correctly with this. It only likes plain txt and carriage returns. Its based in java so I do not know if that helps figure out text encoding.

I would LOVE to be able to put
Code:
FORT=$(/usr/games/fortune)

into

Code:
screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say Backup starting...\r"`"

within the above mentioned formatting. I will give you full credit in the script if you pull this off!
and me and my players will enjoy this very much!


Thanks in advance for any feedback or help!

---------- Post updated at 12:44 AM ---------- Previous update was at 12:41 AM ----------

the hostname of the machine is puffy because I was using freebsd for bit and switched to ubuntu and the hostname carried over. lol.

---------- Post updated at 12:57 AM ---------- Previous update was at 12:44 AM ----------

how do I edit this????
# 2  
Old 08-02-2012
You edit a post by clicking the edit button.

Code:
VAR=$(ps -C java|awk 'FNR == 2 {print $3}')
OLDIFS="$IFS"
IFS=":"
set -- $VAR
IFS="$OLDIFS"

echo "$1 days $2 hours $3 minutes"

I don't know enough about screen to add much about your other question.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Disable minecraft by disabling java

my kids are on minecraft constantly. I want to restrict its use but it seems impossible since it runs on java. :eek: They are using :mad: windows 7 :mad: but I'm asking this question on here since Java is platform independent (er right?):confused: Also this forum was very helpful with my AWK... (10 Replies)
Discussion started by: cmp260
10 Replies

2. Red Hat

Server uptime is showing 0hr but server not rebooted

Hi One of our server is showing the uptime 0hr 5mints there is no log in /var/log/messages there is no log in command "last" kernel version is 2.4.9 (RH2.1 AS) What could be the reason for this. is this issue is related to uptime counter reached max how to verify this. Best Regards KVK (4 Replies)
Discussion started by: venikathir
4 Replies

3. Shell Programming and Scripting

Help with script that reads and writes java console Minecraft

Hi I am looking for an easy way to lock game mode (0) for everyone included op on a Minecraft server. It can be a script that every time a player changes game to 1 the script changes back to 0. What the player writes is visible in the java console. I am not good at script programming and my... (0 Replies)
Discussion started by: MyMorris
0 Replies

4. Linux

uptime command output when the server is running more than one year?

What is the uptime command output when the server is running more than one year? My doubt is whether it show in number of days format or number years and number of days format? For example, Assume the server is running 400 days 3 hrs 3 min 3 secs. The output like 400 days 3:3 min or 1 year 5... (3 Replies)
Discussion started by: maruthu
3 Replies

5. Shell Programming and Scripting

Extract the uptime from the output of the uptime command

Hi! I want to extract the uptime from the output of the uptime command. The output: 11:53 up 3:02, 2 users, load averages: 0,32 0,34 0,43 I just need the "3:02" part. How can I do this? Dirk (6 Replies)
Discussion started by: Dirk Einecke
6 Replies

6. Shell Programming and Scripting

Total number of users logged in a server from uptime

how to find out total number of users logged in a server from uptime . i mean to say i need the total output of unix command . who gives the out put at a particular time . I need at all time from which machine who has connected , (3 Replies)
Discussion started by: amiya.te@gmail
3 Replies

7. Solaris

Server uptime statistics

Hello, I would like to create a report every month about the working hours of some servers. I need to get results such as how long are the servers up every month, which hours/days are up. Do you know any tool which will help me? Thanks in advance (2 Replies)
Discussion started by: @dagio
2 Replies

8. Shell Programming and Scripting

calculate server uptime in % (99.98), using ksh script

Let me preface by saying, I have looked through many threads that deal with keep the decimal, however I'm not sure that any one resolution meets my needs, ok, ok, they could. So maybe it's just that I am not understanding the resolution - therefore I am posting a new thread. myknowledgebase=at... (2 Replies)
Discussion started by: cml2008
2 Replies
Login or Register to Ask a Question