Last active
August 25, 2018 02:12
-
-
Save SilverCory/bbf6e2cd7455d2461cddba17487f5b52 to your computer and use it in GitHub Desktop.
So this is an old old script I wrote from years ago. This enables you to enter commands into a multicraft console and tail the log file. I don't know if it still works, I updated it and added -r to the "read"'s as well as double quotes around variables. All should still be well.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### https://pastebin.com/4pVGcwQE | |
if [ -t 0 ]; then stty sane; fi | |
if [ "$(whoami)" != "root" ]; then echo "This needs to be run as root!" ; exit 0 ; fi | |
echo -n "Username: "; read -r -t 15 username_ | |
ps -au "$username_" ; echo "--------------------------------------------------" | |
echo -n "PID: "; read -r -t 15 PID_ | |
userhome=$(eval echo "~$username_") | |
OldLine="" | |
keypress="" | |
if [[ -f $userhome/logs/latest.log ]]; then | |
logFile="$userhome/logs/latest.log" | |
elif [[ -f $userhome/server.log ]]; then | |
logFile="$userhome/server.log" | |
else | |
if [ -t 0 ]; then stty sane; fi | |
echo "NO LOG FILE FOUND." | |
echo "Exiting." | |
exit 0 | |
fi | |
while true; do | |
if [ -t 0 ]; then stty echo -icanon time 0 min 0; fi | |
keypress='' | |
while [ "x$keypress" = "x" ]; do | |
newLine=$(tail -n 1 "$logFile") | |
if [ "$OldLine" != "$newLine" ]; then | |
OldLine=$newLine | |
echo "$newLine" | |
else | |
OldLine="$newLine" | |
fi | |
read -r keypress | |
done | |
if [[ $keypress = "z" ]]; then | |
if [ -t 0 ]; then stty sane; fi | |
echo -ne "\rExiting.\n" | |
exit 1; | |
fi | |
if [ -t 0 ]; then stty sane; fi | |
echo -en "\rPress z to exit.\n" | |
echo -en "Enter Command>" | |
read -r lol | |
echo "$lol" > "/proc/$PID_/fd/0" | |
echo -en "\033[1A\033[2K\r>$lol\n" | |
done | |
function finish { if [ -t 0 ]; then stty sane; fi } | |
trap finish EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment