Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: Question about Cron

  1. #1

    Question about Cron

    Hi,

    I have a short question about cron which I hope somebody can answer:

    Let's say I have this script which runs for a while (has to do a lot of processing).

    I want to fire this script every 5 minutes.

    If the script is executed at 12:00h and it is still running, will it be executed again at 12:05h? and not wait for the 12:00h to finish.
    Or does it wait, and the 12:00h job finishes at 12:12h and starts the new job at 12:15h

    (I'd like to know, otherwise I have to build some checking wheter or not the script might be running still. )

    TIA.

  2. #2
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    If the script is executed at 12:00h and it is still running, will it be executed again at 12:05h?
    yes

    Or does it wait, and the 12:00h job finishes at 12:12h and starts the new job at 12:15h
    no

    So, you need to analyze ps output to see if your process is still sitting in memory and doing something.

  3. #3
    Join Date
    Apr 2006
    Location
    Heesch, Netherlands
    Posts
    118
    I had a similar problem with my solar monitoring project. (No sun=> no reaction from inverter => waiting until sun comes up...grrr)

    I solved it using:
    Code:
    "Some time consuming command"
    PID=$!
    usleep 1000
    if [ -d /proc/$PID ]
    then
      kill $PID
    fi
    Solar inverter monitoring with Asus wl500gx http://solar.reinieren.net (dutch)

  4. #4
    al37919 and mistraller,

    Thank your very much for your input.

    I will encapsulate some logic to check wheter or not the script is running. .

    thanks again !!..

  5. #5
    Join Date
    Jul 2007
    Location
    Austria
    Posts
    1,336
    well, her is an other solution which I use when a script should start, check himself and exit when running.
    I use it when the first script can not be killed due to some important jobs like backups and it takes longer.

    This script starts and exit himself when pid exists.

    if [ ! -n "`pidof yourscript`" ] ; then
    echo "script not runing"
    #do your job here
    else
    echo "script running"
    #here you do nothing, therefore it ends himself when one instance is running
    fi

    have fun
    Last edited by newbiefan; 23-10-2007 at 22:05.

  6. #6
    Thanks Newbiefan.

    all the bits and pieces are falling together now.

    Greets,

  7. #7

    cron problem

    My cron ron is NOT listed as running process after reboot.
    I have done everything like in this tutorial: http://wl500g.info/showthread.php?t=...rmware&page=25
    This is my process:

    Code:
     PID  Uid     VmSize Stat Command
        1 admin       632 S   /sbin/init
        2 admin           SW  [keventd]
        3 admin           SWN [ksoftirqd_CPU0]
        4 admin           SW  [kswapd]
        5 admin           SW  [bdflush]
        6 admin           SW  [kupdated]
        7 admin           SW  [mtdblockd]
       57 admin       316 S   telnetd
       62 admin       380 S   httpd vlan1
       67 admin       408 S   syslogd -m 0 -O /tmp/syslog.log -S -l 7
       68 admin       364 S   klogd
       71 admin       520 S   nas /tmp/nas.lan.conf /tmp/nas.lan.pid lan
       73 nobody      440 S   [dnsmasq]
       75 admin           SW  [khubd]
       83 admin       276 S   lpd
       85 admin       260 S   p9100d -f /dev/usb/lp0 0
       89 admin       340 S   waveservermain
       91 admin       344 S   rcamdmain
       95 admin           SW  [usb-storage-0]
       96 admin           SW  [scsi_eh_0]
      103 admin       312 S   infosvr br0
      104 admin       476 S   watchdog
      106 admin       344 S   ntp
      124 admin       440 S   udhcpc -i vlan1 -p /var/run/udhcpc0.pid -s /tmp/udhcp
      125 admin       492 S   upnp -D -L br0 -W vlan1
      127 admin       480 S   dropbear
      129 admin       752 S   dropbear
      130 admin       548 S   -sh
      150 admin           SW  [kjournald]
      151 admin           SW  [kjournald]
      153 admin       392 R   ps
      154 admin       132 R   /usr/sbin/vsftpd
    This is my post-boot
    Code:
    #!/bin/sh
    dropbear
    /opt/sbin/cron
    And this is my rc.unslug
    Code:
    #! /bin/sh
    
    # Start/stop all init scripts in /opt/etc/init.d
    # starting them in numerical order and
    # stopping them in reverse numerical order
    #
    if [ $# -ne 1 ]; then
    printf "Usage: $0 {start|stop}\n" >&2
    exit 1
    fi
    
    daemons=`echo $(/usr/bin/dirname $0)/S??*`
    [ $1 = "stop" ] && daemons=`echo $daemons | /usr/bin/tr " " "\n" | /usr/bin/sort -r`
    
    for i in $daemons; do
    
    # Ignore dangling symlinks (if any).
    [ ! -f "$i" ] && continue
    
    # Write to syslog
    logger -t rc.unslung "$1 service $i"
    
    case "$i" in
    *.sh)
    # Source shell script for speed.
    (
    trap - INT QUIT TSTP
    set $1
    . $i
    )
    ;;
    *)
    # No sh extension, so fork subprocess.
    $i $1
    ;;
    esac
    done

  8. #8
    Join Date
    Nov 2004
    Location
    Sweden
    Posts
    259
    have you checked the log (syslog) after starting cron?

  9. #9

    Problems getting cron to execute commands

    I've just recently gotten a WL-500gP V2 and have flashed the newest oleg on it. I'm currently trying to get cron to execute commands. I have cron running in the ps -A list but it will not execute simple commands.


    my current crontab file is
    Code:
    SHELL=/bin/sh
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/sbin:/opt/bin
    HOME=/
    LOGNAME=admin
    1 * * * * date > /tmp/mnt/disc0_3/test.txt
    */1 * * * * /opt/bin/touch /tmp/mnt/disc0_3/test2.txt
    For some reason this does not work. My router user is the default admin. I even tried creating a cron.allow file in cron.d that has admin in it.

    This is driving me nuts and would appreciate any assistance.

  10. #10
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    the answer you wil find in
    PHP Code:
    man 5 crontab 
    It should look like:
    PHP Code:
    */* * * * admin /opt/bin/touch /tmp/mnt/disc0_3/test2.txt 

  11. #11
    Code:
    SHELL=/bin/sh
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/sbin:/opt/bin
    HOME=/
    LOGNAME=admin
    */1 * * * * admin date > /tmp/mnt/disc0_3/test.txt
    */1 * * * * admin /opt/bin/touch /tmp/mnt/disc0_3/test2.txt
    This is my crontab file. I have changed it as al37919 suggested but it still does not work.

    man 5 crontab did not help me to figure out what is wrong. From what I gathered from the man page my crontab should work.

    Code:
    ./opt/etc/crontab
    ./opt/etc/cron.d/cron.allow
    ./opt/etc/cron.d/cron.deny
    ./opt/etc/cron.d
    ./opt/etc/crontab.bak
    ./opt/lib/ipkg/info/cron.prerm
    ./opt/lib/ipkg/info/cron.control
    ./opt/lib/ipkg/info/cron.conffiles
    ./opt/lib/ipkg/info/cron.postinst
    ./opt/lib/ipkg/info/cron.list
    ./opt/bin/crontab
    ./opt/sbin/cron
    ./opt/man/man1/crontab.1
    ./opt/man/man8/cron.8
    ./opt/man/man5/crontab.5
    ./opt/man/man1p/crontab.1p.gz
    ./opt/var/cron/crontabs
    ./opt/var/cron
    ./opt/var/run/cron.pid
    ./usr/bin/crontab
    ./usr/sbin/crond
    I'm not sure if maybe i'm using a wrong file or something so figured i'd post results of find -depth -name cron*. The cron listed in ps is /opt/sbin/cron.


    I am really sorry about requesting so much help but I have just purchased the router and am trying to do the initial setup with out too much luck right now.

  12. #12
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    are there somthing cron-related in the syslog?
    /opt/etc/crontab should have permissions = 600

  13. #13
    there's bultin cron already in oleg's firmware
    create /opt/etc/crontabs directory to place users' crontabs and /opt/etc/init.d/S10crond (chmod it to +x) to start it

    /opt/etc/init.d/S10crond
    Code:
    #!/bin/sh
    
    prefix="/opt"
    PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin
    NAME=crond
    DAEMON=/usr/sbin/${NAME}
    DAEMON_OPTS=""
    DAEMON_DIR=/var/spool/cron
    CRONTABS_DIR=${DAEMON_DIR}/crontabs
    CRONTABS_SRC=${prefix}/etc/crontabs
    
    test -x $DAEMON || exit 0
    
    mkdir -p ${DAEMON_DIR}
    if [ ! -h "${CRONTABS_DIR}" ]; then
        ln -s ${CRONTABS_SRC} ${DAEMON_DIR}
    fi
    
    if [ -z "$1" ] ; then
        case `echo "$0" | sed 's:^.*/\(.*\):\1:g'` in
    	S??*) rc="start" ;;
            K??*) rc="stop" ;;
            *) rc="usage" ;;
        esac
    else
        rc="$1"
    fi
    
    case "$rc" in
        start)
    	echo -e -n "Starting $NAME... "
    	if [ -n "`pidof $NAME`" ]; then
                echo -e "	already running."
    	else
    	    echo -e "	done."
    	    $DAEMON $DAEMON_OPTS
    	fi
            ;;
        stop)
            echo -e -n "Stopping $NAME... "
            if [ -n "`pidof $NAME`" ]; then
    	    echo -e "	done."
                killall $NAME 2> /dev/null
    	else
    	    echo -e "	not running."
            fi
            ;;
        restart)
            "$0" stop
            sleep 1
            "$0" start
            ;;
        *)  
            echo "Usage: $0 (start|stop|restart|usage)"
            ;;
    esac
    /opt/etc/crontabs/admin (user is admin)
    Code:
    #min h d m wday	command
    #--------------	----------------------------------------------
    */30 * * * *	/opt/etc/cron.d/logcleaner
    */1  * * * *	/opt/etc/cron.d/watchdog
    use crontab -l to list crontabls, and crontab -e to edit current jobs

  14. #14

    Question How can I automatically run a script (cron :confused: ) every time WL500gp made a PPP

    How can I automatically run a script (cron ) every time WL500gp made a PPPoE connection (auto connection)?

    Please help

  15. #15
    Join Date
    Jul 2007
    Location
    Austria
    Posts
    1,336
    Quote Originally Posted by Tomason View Post
    How can I automatically run a script (cron ) every time WL500gp made a PPPoE connection (auto connection)?

    Please help
    Well, should be easy - but it depends what you wanna do when there is a valid connection !!
    In any case you must install olegs FW.
    At first read and install: http://www.wl500g.info/showthread.php?t=10307

    For instance: cron is just a program to handle scheduled tasks from a table (like a spreadsheet).
    Example:
    02:30 everyday run as admin a program or script
    08:00 Mo-Fri run as admin wakeonlan_PCx

    But usually a new connection is logged by default.
    Tell us which fw and router you are using and what you wanna do with the information.

    have fun
    Alle HowTo's, all howto's

    RT-N16 1.9.2.7-rtn-r3121, Samba, VSFTP, Lightthpd, PHP, Perl, MySQL, Serendipity, Aria2web, HDD 640GB
    RT-N66U, 16GB MicroSD/ 2 Partitions, 2,5" HDD 1TB, running with Merlin's FW and Entware, 16 Mbit A1,
    Netgear DGND 3700V2, QNAP TS119PII 4 TB, QNAP TS209 2 TB Raid1, Backup Synology DS107+ 1 TB, HP CP1515n

Page 1 of 2 12 LastLast

Similar Threads

  1. Установка RRDTool и CRON на роутер
    By dizzy128 in forum Russian Discussion - РУССКИЙ (RU)
    Replies: 173
    Last Post: 16-04-2012, 17:35
  2. Old two USB Printers question and internet problem.
    By tiagoaleks in forum WL-500gP Q&A
    Replies: 0
    Last Post: 12-09-2007, 11:52
  3. Hide cron from log?
    By Rejan in forum WL-700g Q&A
    Replies: 2
    Last Post: 06-07-2007, 13:57
  4. unslung cron ipkg problem
    By bubieyehyeh in forum WL-HDD Q&A
    Replies: 4
    Last Post: 06-06-2006, 18:06
  5. cron op wl500/g
    By jozef in forum Dutch Discussion - Nederlands
    Replies: 1
    Last Post: 15-04-2006, 19:03

Tags for this Thread

Posting Permissions

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