LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Scripting issue. (https://www.linuxquestions.org/questions/linux-software-2/scripting-issue-93802/)

dolvmin 09-17-2003 10:58 AM

Scripting issue.
 
Hey folks, thanks for reading. I need some help. I run a game server using nwserver from NeverwinterNights. I noticed it is a bit, buggy? Sometimes it goes down. I want to create a script file that detects when it goes down and loads it back up. I'm having difficulty with 1 line. Here's what I got.



#! /bin/bash
# Chris Jepson
# 09-17-03
# ./autostart.dat
# This file detects the status of nwserver & if down, restarts it.


STATUS=ps -A > status.mem
FILTER=grep -o nwserver status.mem > filter.mem
PROCESS= # *My problem! input text from file "filter.mem" into memory.

LOOP=1

while ["$LOOP"!=0 ]

do

sleep 6

$STATUS # Check all processes
$FILTER # Filter for process nwserver


case $PROCESS in # check for nwserver in varable.

[nwserver]) clear;; # nwserver in varable, do nothing.

*) ./start.nwn;; # nwserver not in varable, restart it.

esac


done



I need to get the text in the file "filter.mem" into memory as if I was to use "read PROCESS" and type it in manually. That way my case statement would work. Could someone help please?

unSpawn 09-17-2003 11:17 AM

You're better off running "monit". Check freshmeat.net for it.

dolvmin 09-17-2003 12:11 PM

As powerful and interesting as this monit program may be, I would still like to know what I am doing wrong with my own script.

I'm running the game server, not just for enjoyment but, also for practice in administration w/ Linux. I want to learn as much as I can within the field. Monit may be freeware, but it is also lisenced software. If I was in a corperation, installing it could lead to my termination. Most corperations now higher admins who have some programing experience as well. They want the admins to create script files. They would not settle for Monit until after they had me complete a script file first.

Besides, this script program I am trying to make is only a peice of the entire thing I'm making. I already have 3 scripts up, including a menu, a database to allow me to see which players are logged on by using grep & ark within the nwserver log file and more. Monit does not do this for me. In addition, my script files work in command line, some do not work in the xwindows and most administration w/ Linux is done the same way. Monit is a great tool, but not for me right now.

I also need to practice providing access rights to remote login users on ssh. I can already see that Monit is confusing the living hell out of me, in that dept. Though Monit does support ssh, it's complexity is throwing me off. I may mistakenly give to much rights to someone undeserving of it, if I use Monit. I don't want that make that mistake.

Is there a way I can foward text information from a file, into memory?

unSpawn 09-17-2003 12:41 PM

As powerful and interesting as this monit program may be, I would still like to know what I am doing wrong with my own script.
Let's say you're using the wrong method. I could transmogrify your script, but this is easier, because you'll use tools for process listing:

#!/bin/bash
proc=nwserver; while [ "X$(pgrep $proc -d " ")" != "X" ]; do pgrep $proc -d " " >/dev/null && echo $proc is running... || ./start.nwn; sleep 30s; done

Monit may be freeware, but it is also lisenced software. If I was in a corperation, installing it could lead to my termination.
WTF? Monit is GPL'ed!

I also need to practice providing access rights to remote login users on ssh. I can already see that Monit is confusing the living hell out of me, in that dept. Though Monit does support ssh, it's complexity is throwing me off. I may mistakenly give to much rights to someone undeserving of it, if I use Monit. I don't want that make that mistake.
Caution is good, but you're confusing things.

dolvmin 09-17-2003 05:52 PM

Open the script files for monit. It refers to copyrights.

I'll check out what you gave me... Thanks for the info.

dolvmin 09-17-2003 09:54 PM

This statement works halfway.
It does report if nwserver is running.
It however, does not restart the server or report nwserver down.

I tried replacing the ./start.nwn with TEST=1

Then did a echo "$TEST"
read PAUSE
PAUSE=""

TEST showed up as absolutely nothing.
It did not print $proc(nwserver) is running.
nwserver "did" go down.

Can you explain to me how you are getting the result of a command into the memory?

dolvmin 09-17-2003 10:01 PM

Oh boy. Well, I got it to auto start. <smiles> Give me a moment though, I need to verify it works both ways now.

dolvmin 09-17-2003 10:09 PM

LINE: while [ "X$(pgrep $proc -d " ")" != "X" ]
SHOULD BE: while [ "X$(pgrep $proc -d "")"!="X" ]

THe spaces were causing the problem. Common mistake but very entertaining! <smiles>

Thanks abunch. It works 100% now.

dolvmin 09-18-2003 10:28 PM

Dude!

I had a class today with a suprise quiz.

One of the things we needed to do is setup our "bashrc" file to load up:

Good afternoon, Chris. < if it's PM

Good morning, Chris. < if it's AM


If it was not for you, I would have never guessed it!

I put alittle thought into it and came up with this string! IT WORKED!

if [ "$(date +%p)" != "PM" ];then
echo "Good morning, $USER."

else
echo "Good afternoon, $USER."

fi

Thanks so much! <smiles>:D


All times are GMT -5. The time now is 06:34 AM.