ďťż
 
 
   [+] cron i uruchomienie skryptów
 
 

Tematy

 
    
 

 

 

 

[+] cron i uruchomienie skryptów





szpecu - 22-04-2010 12:05
Witam.
Posiadam Debiana Lenny. Wrzuciłem do crona 3 skrypty.

Pierwszy skrypt: #!/usr/bin/php
<?php

#
# Sprawdzanie procesu ventrilo_srv
# v.1.0
#

function pid_check ($nazwaprogramu, $id)
{

  $buf = `ps -C $nazwaprogramu -o pid=`;
  @preg_match_all('/([0-9]+)/', $buf, $tab);
  #print_r($tab);
  $v = 0;
  foreach ($tab[1] as $v)
  {
      if ($id == $v) {$v = 1;}
  }
  if ($v == 1) {return true;} else {return flase;}

}

function file_check ($dir="/home/ventrilo")
{

  $buf = `find $dir -name "ventrilo_srv\.pid"`;
  @preg_match_all('/(.+)/', $buf, $tab);

  foreach ($tab[1] as $v)
  {

      $id = file_get_contents($v);
     
      if (@pid_check("ventrilo_srv", $id))
      {
          print "OK PID: $v\n";
      }
        else
      {
          print "ERROR PID: $v\n";
          @unlink($v);
      }

  }

}

function proces_check ()
{

  $buf = `ps -C ventrilo_srv fo pid,command`;
  @preg_match_all('/([0-9]+)\s(.+)/', $buf, $tab);
  $i = 0;

  foreach ($tab[1] as $v)
  {
      $t = explode(" ", trim($tab[2][$i]));
      $file_pid = $t[0].".pid";
      if (!@file_exists($file_pid) OR (filesize($file_pid) == 0))
      {
          echo `echo "$v" > $file_pid`;
          echo "Dodano PID:".$v." > ".$file_pid."\n";
      }     
      $i++;
  }

}

@file_check();
@proces_check();

?> Drugi skrypt: #!/usr/bin/php
<?php

include('/var/www/panel/config.php');

// sprawdzanie daty
function date_diff($date1, $date2)
{

$d1 = explode("-", $date1);
$y1 = $d1[0];
$m1 = $d1[1];
$d1 = $d1[2];

$d2 = explode("-", $date2);
$y2 = $d2[0];
$m2 = $d2[1];
$d2 = $d2[2];

$date1_set = mktime(0,0,0, $m1, $d1, $y1);
$date2_set = mktime(0,0,0, $m2, $d2, $y2);

return(round(($date2_set-$date1_set)/(60*60*24)));
}
// -----

// Pobieranie informacji o czasie pracy serwera.
$UpTime = file('/proc/uptime');
$UpTime = $UpTime[0];

// Formatowanie danych...
$UpSecs = floor($UpTime % 60);
$UpMins = floor($UpTime / 60 % 60);
$UpHours = floor($UpTime / 3600 % 24);
$UpDays = floor($UpTime / 86400);

$UpTime = 'Czas pracy serwera: ';

if ($UpDays > 0)
  {
  $UpTime .= $UpDays;
  $UpTime .= ' d ';
  }
if ($UpHours > 0)
  {
  $UpTime .= $UpHours;
  $UpTime .= ' h ';
  }
if ($UpMins > 0)
  {
  $UpTime .= $UpMins;
  $UpTime .= ' m ';
  }
if ($UpSecs > 0)
  {
  $UpTime .= $UpSecs;
  $UpTime .= ' s';
  }

// Włączanie i wyłączanie serwerów.

if (($UpDays==0) && ($UpHours==0) && ($UpMins==2)) {

$sql = "select * from `vt_users` order by `port` ASC";
$zapytanie = mysql_query($sql);
while($row = mysql_fetch_array($zapytanie))
    {$date=date_diff(date("Y-m-d"), $row['data']);
        if($date<0)$data=''; else {

        unlink('/home/ventrilo/'.$row['port'].'/ventrilo_srv.pid');
    }
}

sleep(10);

$sql = "select * from `vt_users` order by `port` ASC";
$zapytanie = mysql_query($sql);
while($row = mysql_fetch_array($zapytanie))
    {$date=date_diff(date("Y-m-d"), $row['data']);
        if($date<0)$data=''; else {

            if(!eregi($row['port'],@file_get_contents('/tmp/ventrilo_start')) and !file_exists('/home/ventrilo/'.$row['port'].'/ventrilo_srv.pid')){
            $f = fopen('/tmp/ventrilo_start','a');
            if(fwrite($f, $row['port']."\n"))
            fclose($f);
            $sql="select `id` from `vt_users` where `port`='".$row['port']."'";
            $wiersz=mysql_fetch_array(mysql_query($sql));

                $sql="insert into `vt_logi` SET `user_id`='".$wiersz['id']."', `ip`='127.0.0.1', `data`='".date("Y-m-d H:i:s")."', `login`='SuperAdmin', `tresc`='1'";
                mysql_query($sql);

    }
}
}
}else
{
echo $UpTime;
}

?> Trzeci skrypt:
#!/bin/bash
# zatrzymywanie serwerów
if [ -e "/tmp/ventrilo_stop" ]
then
cp /tmp/ventrilo_stop /tmp/ventrilo_stop_b
echo " ">/tmp/ventrilo_stop

    for x in $(cat /tmp/ventrilo_stop_b)
    do
        if [ -n "$x" ]
        then
    echo $x
                    b=${x#*;}
                    a=${x%;*}

                    kill -9 "$a"
                    rm "/home/ventrilo/$b/ventrilo_srv.pid"
        fi
    done
    rm /tmp/ventrilo_stop_b
fi

# uruchamianie serwerów
if [ -e "/tmp/ventrilo_start" ]
then
cp /tmp/ventrilo_start /tmp/ventrilo_start_b
echo " ">/tmp/ventrilo_start
    for x in $(cat /tmp/ventrilo_start_b)
    do
            if [ -n "$x" ]
            then
                    /home/ventrilo/$x/ventrilo_srv -f/home/ventrilo/$x/ventrilo_srv >/dev/null &
                    sleep 2
                    chmod 777 "/home/ventrilo/$x/ventrilo_srv.pid"

            fi
    done
    rm /tmp/ventrilo_start_b
fi A o to logi, które mi cron wysyła:
From root@cs.localdomain  Thu Apr 22 10:03:02 2010
Return-Path: <root@cs.localdomain>
X-Original-To: root
Delivered-To: root@cs.localdomain
Received: by cs.localdomain (Postfix, from userid 0)
    id 65F881E7A7EA; Thu, 22 Apr 2010 10:03:01 +0000 (UTC)
From: root@cs.localdomain (Cron Daemon)
To: root@cs.localdomain
Subject: Cron <root@cs> /var/www/files/1.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20100422100302.65F881E7A7EA@cs.localdomain>
Date: Thu, 22 Apr 2010 10:03:01 +0000 (UTC)

/bin/sh: /var/www/files/1.sh: /usr/bin/php^M: bad interpreter: No such file or directory

From root@cs.localdomain  Thu Apr 22 10:03:03 2010
Return-Path: <root@cs.localdomain>
X-Original-To: root
Delivered-To: root@cs.localdomain
Received: by cs.localdomain (Postfix, from userid 0)
    id C3D2C1E7A7CE; Thu, 22 Apr 2010 10:03:01 +0000 (UTC)
From: root@cs.localdomain (Cron Daemon)
To: root@cs.localdomain
Subject: Cron <root@cs> /var/www/files/sprawdz.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20100422100302.C3D2C1E7A7CE@cs.localdomain>
Date: Thu, 22 Apr 2010 10:03:01 +0000 (UTC)

/bin/sh: /var/www/files/sprawdz.sh: /bin/bash^M: bad interpreter: No such file or directory Nie wiem, czego możne być to wina?
Pozdrawiam i dziękuje z góry za pomoc.



lessmian2 - 22-04-2010 12:21
/bin/sh: /var/www/files/1.sh: /usr/bin/php^M: bad interpreter: No such file or directory Masz zły znacznik końca linii. Popraw i będzie ok. Nie pisałeś czasem pod Windowsem i skopiowałeś pliki na Linuksa?



szpecu - 22-04-2010 12:32
Ja tego skryptu nie napisałem, a osoba która go napisała teraz już mi pomoc nie chce. A mógłbyś mi wskazać gdzie ten znacznik znajdę? Jak tak przeglądam przez nano to nic takiego tam nie ma.
/usr/bin/php^M



lessmian2 - 22-04-2010 12:38
Zainstaluj pakiet tofrodos i spróbuj: dos2unix skrypt.php Sprawdź czy dalej pluje błędami.



szpecu - 22-04-2010 12:48
dos2unix: Unable to access file skrypt.php. Takie coś się wyświetliło.

A to mail od crona: From root@cs.localdomain  Thu Apr 22 10:46:02 2010
Return-Path: <root@cs.localdomain>
X-Original-To: root
Delivered-To: root@cs.localdomain
Received: by cs.localdomain (Postfix, from userid 0)
    id F005A1E7A7EA; Thu, 22 Apr 2010 10:46:01 +0000 (UTC)
From: root@cs.localdomain (Cron Daemon)
To: root@cs.localdomain
Subject: Cron <root@cs> /var/www/files/sprawdz.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20100422104601.F005A1E7A7EA@cs.localdomain>
Date: Thu, 22 Apr 2010 10:46:01 +0000 (UTC)

/bin/sh: /var/www/files/sprawdz.sh: /bin/bash^M: bad interpreter: No such file or directory

From root@cs.localdomain  Thu Apr 22 10:47:02 2010
Return-Path: <root@cs.localdomain>
X-Original-To: root
Delivered-To: root@cs.localdomain
Received: by cs.localdomain (Postfix, from userid 0)
    id BF2B91E7A7EA; Thu, 22 Apr 2010 10:47:01 +0000 (UTC)
From: root@cs.localdomain (Cron Daemon)
To: root@cs.localdomain
Subject: Cron <root@cs> /var/www/files/sprawdz.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20100422104702.BF2B91E7A7EA@cs.localdomain>
Date: Thu, 22 Apr 2010 10:47:01 +0000 (UTC)

/bin/sh: /var/www/files/sprawdz.sh: /bin/bash^M: bad interpreter: No such file or directory Czyli teraz pluje o basha.



lessmian2 - 22-04-2010 12:53
Mama nadzieję, że zamiast skrypt.php wstawiłeś ścieżkę do swojego skryptu? Wykonaj w terminalu: dos2unix /var/www/files/1.sh
dos2unix /var/www/files/sprawdz.sh



szpecu - 22-04-2010 13:01
Dziękuję Ci bardzo. Wszystko ładnie działa.
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • minister.pev.pl

  •  

     


     

     
    Copyright 2003. MĂłj serwis