Find the answer to your Linux question:
Results 1 to 9 of 9
So I am thinking of switching from a windows server to a linux server. I use my windows server for remote desktop, ftp, web, and also as a source dedicated ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    4

    Post Shell script help


    So I am thinking of switching from a windows server to a linux server.
    I use my windows server for remote desktop, ftp, web, and also as a source dedicated server.

    I can replace remote desktop with vnc, I'm sure there is an easy ftp program for linux, I can use apache server for web, and I know that source makes a linux dedicated server.

    My only problem is that on my windows server, I made a batch file that searched the tasklist for srcds.exe (source dedicated server) and wrote an htm file saying "Online" with green font if it found the program in the tasklist, and "offline" with red font if it didn't. Then had the batch file output a vbs file and running it. The vbs file is so that the computer waits for however long, and then it loops.

    Then on my homepage I said "The l4d2 server is:" and then used an iframe to display the htm file that the batch file outputed.

    SO Anyway, I was wondering if someone could make a shellscript similar to the batch file I made. Below is the contents of the batch file.

    Code:
    :Start
    
    echo ^<html^> ^<body bgcolor="black"^> ^<font color="green"^> Online ^</body^> ^</html^> >"c:\inetpub\wwwroot\status.htm"
    
    tasklist /FI "IMAGENAME eq srcds.exe" | find /i "srcds.exe"
    if ERRORLEVEL 1 echo ^<html^> ^<body bgcolor="black"^> ^<font color="red"^> Offline ^</body^> ^</html^> >"c:\inetpub\wwwroot\status.htm"
    
    
    echo wscript.sleep 10000>"l4d2_wait.vbs"
    cscript l4d2_wait.vbs
    del l4d2_wait.vbs
    
    goto start

    Edit: Forgot to mention that I plan to use Ubuntu Linux desktop, not server. Because I enjoy the gui. If that helps at all.

  2. #2
    Linux Newbie
    Join Date
    Apr 2007
    Posts
    119
    Here is a great bash scripting guide. i am sure you can change your batch file over.

  3. #3
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    Or you integrate this query into a general monitoring like it is mostly used by system administrators that monitor servers / services he has to manage. You'll just have to get familiar with some other language like Perl.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jul 2010
    Posts
    4

    Thanks

    @markcole
    I'll have to read it and go through some of the examples.
    I skimmed over it and I can tell that it will help alot. Thanks.

    -------------------------------------------------------------------------------

    @Kloschüssel
    Can you please tell me more? I think I like what I am hearing, but I don't know if I want to learn Pearl. Is there a way I could do this using c# or visual basic on linux?
    I have never used an IDE on linux before, just windows. So you should get back to me.
    Last edited by GoldenPotato; 07-23-2010 at 10:59 PM. Reason: idk

  6. #5
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    you can basically realize a monitoring by whichever means you like. i don't see why it wouldn't be possible with c#. certainly you won't be able to deploy a monitoring thingy on a linux box when it needs .net, but that's another story.

    i thought of a monitoring that would run certain jobs regularily. these jobs return a status (fail, success) and a message containing the explanation for a fail. install that thingy on a server and let it bail alarms when a fail is generated.

    well, you'll certainly understand what I am talking of. and you may find a tool that provides these kind of things or make your own. should not take longer than a few days.

    greetings

  7. #6
    Just Joined!
    Join Date
    Jul 2010
    Posts
    4
    Well that would be nice, but I want something simple.
    Something that senses when a program is or is not running, and writes the appropriate text into a file.

    Appropriate text meaning <html> <body bgcolor="black"><font color="red">offline</font></body></html>

    or

    <html> <body bgcolor="black"><font color="green">online</font></body></html>

    Like my batch file. Simple.
    So in windows I could use the command
    tasklist /FI "IMAGENAME eq srcds.exe" | find /i "srcds.exe"
    and view the errorlevel of the command tasklist by going
    if ERRORLEVEL 1 "right here i would put the echo command writing the 'offline' message".

    because if the errorlevel is 1 that means that the command tasklist could not find the specified task.



    If I had something as simple of a tasklist command in the linux shell, I would be happy.

  8. #7
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    just because a task is alive, it doesnt mean it is running. it could be deadlocked or in any other exceptional state that prevents it from working.

    if you want to test if something is truely working, you have to implement some logic that grasps that information. for a database it would be a checklist like:
    * server ping
    * database started
    * database select works

  9. #8
    Just Joined!
    Join Date
    Jul 2010
    Posts
    4
    Oh! That would be nice. The left4dead2 dedicated server program does lockup because it can't find a player model or it's out of date and it would be nice to detect that and state that the server is offline untill the problem is resolved or the dedicated server program is restarted.

  10. #9
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    I see you grasped the point. That said, I can't provide you with a framework or something else that does this job, so you'll have to do some things on your own. I just don't know any framework that does this.

    So I would recommend you start off with googling if there is something that matches the requirements. If you can't find anything until today at, let's say 18°° (UTC+1), post here and I can start off a open source project for you. There I'll implement you the framework how it should be done (should not take longer than 3 hours) and you can afterwards implement the tests you need.

    And after all lots of people will be grateful for that work.



    EDIT: jasmo - Project Hosting on Google Code
    Last edited by Kloschüssel; 07-27-2010 at 05:12 PM.

Posting Permissions

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