Linux script

This is a discussion on Linux script within the Linux Programming forums, part of the Platform Specific Boards category; I once made this script which used CRON to be run every minute. Here's what the script did: I ran ...

  1. #1
    Registered User deltabird's Avatar
    Join Date
    Jan 2003
    Posts
    73

    Linux script

    I once made this script which used CRON to be run every minute. Here's what the script did:

    I ran a game server for a game called Neverwinter Nights. If the server crashed and I wasn't home, I couldn't reset it and all my regular players would be out of luck until I could put the server back up. So I wrote this script that did something like "grep" and check the results for a certain string. If the string was found, then I the server was running. If the string was not found, it would execute the command to start up the server. I lost that script, and haven't done anything in linux since. Now a friend wants it who runs a server.

    Could somebody just write some pseudo code for me for how to do this? And any linux-specific commands I'll need in writing it?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    There's probably better ways, but here's one:
    Code:
    #!/bin/bash
    
    PROG=junk
    typeset -i num  # if your shell supports it
    
    num=$(ps -ef|grep $PROG|wc -l)
    
    echo "$num instances of program $PROG running"
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 12:03 PM
  2. Linux: Use C to call a bash script
    By harada in forum Linux Programming
    Replies: 9
    Last Post: 10-27-2006, 02:59 PM
  3. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM
  4. Game structure, any thoughts?
    By Vorok in forum Game Programming
    Replies: 2
    Last Post: 06-07-2003, 02:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21