Keresés

Hirdetés

Új hozzászólás Aktív témák

  • vargalex

    Topikgazda

    válasz h0ri #27335 üzenetére

    Hi!

    Kipróbáltam, nincs vele semmi gond.

    Crontab file:

    root@OpenWrt:~# cat /etc/crontabs/root
    33 * * * * /etc/crontabs/mdlnb
    34 * * * * /etc/crontabs/mdlnb
    35 * * * * /etc/crontabs/mdlnb

    A script (kicsit átírtam, kibővítettem - ha fut a miniDLNA, akkor leállítja, ha nem, akkor indítja, valamint logol a syslog-ba):

    root@OpenWrt:~# cat /etc/crontabs/mdlnb
    #!/bin/sh
    minidlna_check()
    {
    PID=$(pidof minidlna)
    if [ -n "$PID" ]; then
    logger -t mycrontab "miniDLNA is active, PID: $PID.";
    return 1;
    else
    logger -t mycrontab "miniDLNA is not active.";
    return 0;
    fi
    }

    minidlna_check
    if [ $? -eq 1 ]; then
    logger -t mycrontab "Stopping miniDLNA."
    /etc/init.d/minidlna stop
    else
    logger -t mycrontab "Starting miniDLNA."
    /etc/init.d/minidlna start
    fi
    minidlna_check

    A keletkezett log bejegyzések:

    May 30 10:33:01 OpenWrt cron.info crond[31065]: crond: USER root pid 31216 cmd /etc/crontabs/mdlnb
    May 30 10:33:01 OpenWrt user.notice mycrontab: miniDLNA is not active.
    May 30 10:33:01 OpenWrt user.notice mycrontab: Starting miniDLNA.
    May 30 10:33:01 OpenWrt user.notice mycrontab: miniDLNA is active, PID: 31226.
    May 30 10:34:01 OpenWrt cron.info crond[31065]: crond: USER root pid 31236 cmd /etc/crontabs/mdlnb
    May 30 10:34:01 OpenWrt user.notice mycrontab: miniDLNA is active, PID: 31226.
    May 30 10:34:01 OpenWrt user.notice mycrontab: Stopping miniDLNA.
    May 30 10:34:02 OpenWrt user.notice mycrontab: miniDLNA is not active.
    May 30 10:35:01 OpenWrt cron.info crond[31065]: crond: USER root pid 31254 cmd /etc/crontabs/mdlnb
    May 30 10:35:01 OpenWrt user.notice mycrontab: miniDLNA is not active.
    May 30 10:35:01 OpenWrt user.notice mycrontab: Starting miniDLNA.
    May 30 10:35:01 OpenWrt user.notice mycrontab: miniDLNA is active, PID: 31264.

    Illetve csináltam egy olyat is, ahol közben egyszer manuálisan leállítottam (a futtatást átírtam 42,43,44-re, 10:42:10-kor állítottam le kézzel). Ekkor a keletkezett log:

    May 30 10:42:01 OpenWrt cron.info crond[31065]: crond: USER root pid 31327 cmd /etc/crontabs/mdlnb
    May 30 10:42:01 OpenWrt user.notice mycrontab: miniDLNA is not active.
    May 30 10:42:01 OpenWrt user.notice mycrontab: Starting miniDLNA.
    May 30 10:42:01 OpenWrt user.notice mycrontab: miniDLNA is active, PID: 31337.
    May 30 10:43:01 OpenWrt cron.info crond[31065]: crond: USER root pid 31357 cmd /etc/crontabs/mdlnb
    May 30 10:43:01 OpenWrt user.notice mycrontab: miniDLNA is not active.
    May 30 10:43:01 OpenWrt user.notice mycrontab: Starting miniDLNA.
    May 30 10:43:01 OpenWrt user.notice mycrontab: miniDLNA is active, PID: 31367.
    May 30 10:44:01 OpenWrt cron.info crond[31065]: crond: USER root pid 31374 cmd /etc/crontabs/mdlnb
    May 30 10:44:01 OpenWrt user.notice mycrontab: miniDLNA is active, PID: 31367.
    May 30 10:44:01 OpenWrt user.notice mycrontab: Stopping miniDLNA.
    May 30 10:44:02 OpenWrt user.notice mycrontab: miniDLNA is not active.

    Látszik, hogy az első két futás-nál miniDLNA start történt, ahogy várható is volt.

    Megjegyzem, hogy a futtatandó scriptet nem szép dolog a /etc/crontabs könyvtárba tenni. Ott, ahogy az elnevezése is mutatja, a crontab-ok helye van.

    [ Szerkesztve ]

    Alex

Új hozzászólás Aktív témák