Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Utorok, 3. december 2024

Súbor: [Platon] / scripts / shell / autorun / autorun.old.sh (stiahnutie)

Revízia 1.1, Sat Feb 16 20:26:04 2002 UTC (22 years, 9 months ago) by jombik9

Autorun script.

#!/bin/bash

# autorun.sh by Ondrej Jombik, 22.9.2000

# Toto je autorun-script na kontrolu nahodeneho scriptu. Funguje tak, ze
# ku kazdemu scriptu, ktory chceme kontrolovat musime vytvorit jeden
# takyto autorun-script. Tento autorun-script zapiseme do crontab. Potom 
# bude v pravidelnych casovych intevaloch kontrolovat nas script, ci bezi. 
# Pokial script nebezi, tak ho autorun-script znovu nahodi.

# Adresar spustaneho scriptu.
scriptdir="$HOME/autorun/"

# Nazov spustaneho scriptu.
script="maxzaw.sh"

#############################################################################

cd $scriptdir

# Existuje PID subor?
if [ -r $script.pid ]; then
  scriptpid=`cat $script.pid`
  if `kill -CHLD $scriptpid >/dev/null 2>&1`; then
    exit 0
  fi
  echo "PID file '$script.pid' found."
  echo "Invalid PID ($scriptpid), script '$script' probably not running."
  echo "Removing '$script.pid'."
  rm -f $script.pid
else
  echo "PID file '$script.pid' not found, script '$script' not running." 
fi

# PID subor neexistuje. Vytvorime ho.
# K tomu potrebujeme jeden specialny externy program.

# Existuje tento program?
if [ -r get_parent_pid ]; then
  echo "Program 'get_parent_pid' found."
else
  echo "Program 'get_parent_pid' not found."
  echo "Creating '$script.get_parent_pid.c'."
  echo -E "#include<stdio.h>" > $script.get_parent_pid.c
  echo -E "#include<unistd.h>" >> $script.get_parent_pid.c
  echo -E "int main(void){printf(\"%d\n\",getppid());return(0);}" >> $script.get_parent_pid.c
  echo "Compiling '$script.get_parent_pid.c', creating program 'get_parent_pid'."
  cc -Wall $script.get_parent_pid.c -o get_parent_pid 
fi

# Odstranime zdrojaky
if [ -r $script.get_parent_pid.c ]; then
  echo "Removing '$script.get_parent_pid.c'."
  rm -f $script.get_parent_pid.c
fi

# Vytvorime PID subor.
echo "Using program 'get_parent_pid', creating '$script.pid'."
./get_parent_pid > $script.pid

# Nahodime script.
echo "Running '$script'."
./$script

# Script skoncil. Zmazeme PID.
echo "Script '$script' finished (killed), removing PID file '$script.pid'."
rm -f $script.pid

# Koncime.
echo "Terminating..."
exit 0

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok