Log in

Bekijk de volledige versie : Question about Cron



raas
23-10-2007, 19:37
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.

al37919
23-10-2007, 20:17
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.

mistraller
23-10-2007, 21:28
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:


"Some time consuming command"
PID=$!
usleep 1000
if [ -d /proc/$PID ]
then
kill $PID
fi

raas
23-10-2007, 21:43
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 !!..

newbiefan
23-10-2007, 22:03
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

raas
24-10-2007, 21:49
Thanks Newbiefan.

all the bits and pieces are falling together now.

Greets,

kierzniak
24-08-2008, 18:52
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=10307&highlight=backup+firmware&page=25
This is my process:


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


#!/bin/sh
dropbear
/opt/sbin/cron


And this is my rc.unslug

#! /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

Tamadite
25-08-2008, 18:48
have you checked the log (syslog) after starting cron?

smarttowers
06-12-2008, 20:03
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


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.

al37919
06-12-2008, 20:41
the answer you wil find in

man 5 crontab
It should look like:

*/1 * * * * admin /opt/bin/touch /tmp/mnt/disc0_3/test2.txt

smarttowers
07-12-2008, 08:26
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.




./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.

al37919
07-12-2008, 13:12
are there somthing cron-related in the syslog?
/opt/etc/crontab should have permissions = 600

theMIROn
07-12-2008, 14:19
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


#!/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)


#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

Tomason
19-09-2009, 14:43
How can I automatically run a script (cron :confused: ) every time WL500gp made a PPPoE connection (auto connection)?

Please help :D

newbiefan
20-09-2009, 11:18
How can I automatically run a script (cron :confused: ) every time WL500gp made a PPPoE connection (auto connection)?

Please help :D

Well, should be easy - but it depends what you wanna do when there is a valid connection !!:D:D
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

Tomason
20-09-2009, 11:39
OK.

I own a WL500gp, with WL500gp-1.9.2.7-d-r599.trx (http://code.google.com/p/wl500g/)

I want to send to myself an email with the router IP after each login to PPPoE (login automaticaly or manualy).

I put that "command" to /tmp/local/sbin/post-firewall, but maybe there is a better solution.

newbiefan
20-09-2009, 21:33
I put that "command" to /tmp/local/sbin/post-firewall, but maybe there is a better solution.

?? Which command?
Well, what do you expect? I guess there is nobody who want to do everything for you.

So you have to use the search function, install what you need and write your own script.

I would suggest to install at first according wengis howto - further I can help you a bit with scripting, but you must determine the needed software and manuals and how you want to do the things.

Have a look at this list - all this is available for your router.
http://ipkg.nslu2-linux.org/feeds/optware/oleg/cross/stable/Packages

for instance: esmtp could be useful......

have fun

Tomason
21-09-2009, 09:45
Thank you for nothing :mad:

I love this forum, a lot of questions whitout answers...

For your information I used search function, I tryed to do it myself but I need some help.

I have a solution that is working, but maybe there is a better solution.

Maybe somebody else can help me, or not :D

The question is:
If I want to execute a script every time the router establishes a connection (PPPoE) automaticaly or manualy, where must I put this script?

If somebody can / want to help I say THANK YOU.

:D

newbiefan
21-09-2009, 19:29
The question is:
If I want to execute a script every time the router establishes a connection (PPPoE) automaticaly or manualy, where must I put this script?

If somebody can / want to help I say THANK YOU.

:D

Well, just do a

echo $PATH

those are the places where you can store the script....on any linux....
be aware, when storing the script into routers flash, you must store the path to your script too: (for example)

echo /usr/sbin/yourscript >> /tmp/local/.files
chmod 755 /usr/sbin/yourscript
flashfs save
flashfs commit
flashfs enable
reboot

When storing to /opt/sbin or opt/bin just store your script, nothing else is needed.

Do not forget to make your script executeable:
[
chmod 755 /where_your_script_is/name_of_script

Thats it!
As you already have a working solution and it seems that you know already linux, it should not be a big deal. :D

Further, you can store your script anywhere, just make script executeable and use full path when calling your script.
Would be nice to let us know, how you got your solution working...:o

In case that nothing is installed according wengis howto or similar , it will be a hard task.:eek:

Have fun.....

Tomason
22-09-2009, 10:23
OK, but where is the ...

.. every time the router establishes a connection (PPPoE) automaticaly or manualy ..
:confused:

DrChair
22-09-2009, 11:13
OK, but where is the ...

.. every time the router establishes a connection (PPPoE) automaticaly or manualy ..
:confused:

Normally you would name the script ip-up and place it in /etc/ppp

Tomason
22-09-2009, 11:27
There is a /tmp/ppp/ip-up (and ip-down) = symlink to /sbin/rc


AND you mean I must create a new subdirectory ppp in directory etc, with ip-up inside?

/etc/ppp/ip-up = /tmp/etc/ppp/ip-up

THANK YOU
:D

velcrow
22-09-2009, 11:52
And to help some more here is what I use to send a email.

http://wl500g.info/showthread.php?p=119188&#post119188