LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 07-10-2011, 01:38 PM   #1
Alan87i
Member
 
Registered: Oct 2005
Location: Quebec
Posts: 119

Rep: Reputation: 15
Cron job issues


I have set up a couple of jobs to start 2 scripts every morning at 6:30 . But wih in an hour or so both jobs have stopped ?

How can i make them run all day for 15 hours then stop at night at 21:30 Witch I also have made a script to stop them Than works If I manually start them both they run all day till 21:30.
 
Old 07-10-2011, 02:29 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Do you know why your scripts are stopping within an hour? If you can stop them stopping then they will run until you stop them which could be done in several ways including a cron job to send them a signal.
 
Old 07-10-2011, 03:39 PM   #3
Alan87i
Member
 
Registered: Oct 2005
Location: Quebec
Posts: 119

Original Poster
Rep: Reputation: 15
crontab -l
Code:
allan@allan-cameras:~$ crontab -l
30 21   * * *   allan   /killalarm.sh
30 6    * * *   allan   /zmalarm.sh
30 6    * * *   allan   /zmalarm2.sh
#allan@allan-cameras:~$
if I run both zmalarm scripts manually they run all day till 21:30 when the kill script runs. If cron starts them in the morning last few days I've checked and by 8 or so AM both scripts are stopped.
 
Old 07-10-2011, 06:20 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by Alan87i View Post
If cron starts them in the morning last few days I've checked and by 8 or so AM both scripts are stopped.
Understood. Do you know why they are stopping within an hour?
 
Old 07-11-2011, 08:48 AM   #5
Alan87i
Member
 
Registered: Oct 2005
Location: Quebec
Posts: 119

Original Poster
Rep: Reputation: 15
No idea why they stop . Must be something to do with cron . Because if I manually execute them they run all day.
It happened again this morning I noticed it was over 1 hour but both scripts stopped running.
I'm running xubuntu 8.04.1 LTS.
Is there any other program besides cron that can execute a script ?
 
Old 07-11-2011, 10:16 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by Alan87i View Post
Is there any other program besides cron that can execute a script ?
at, anacron, shells (such as bash), scripts (such as bash, awk, perl ...), and any other program that can use the exec family of system calls (which is most commonly provided by a system function/object in the language).

cron is so widely used that it is unlikely to be setting up a process environment which will cause a script it has started to fail -- unless the script tries to read from stdin or write to stdout or stderr. You could try changing the cron job line command to something like
Code:
myscript.sh < /dev/null > myscript.stdout 2> myscript.stderr
EDIT: except that too will fail if the current directory is not writeable. Maybe better
Code:
myscript.sh < /dev/null > /tmp/myscript.stdout 2> /tmp/myscript.stderr

Last edited by catkin; 07-11-2011 at 10:18 AM.
 
Old 07-12-2011, 08:20 AM   #7
Alan87i
Member
 
Registered: Oct 2005
Location: Quebec
Posts: 119

Original Poster
Rep: Reputation: 15
Again today both scripts start and run pstree -p shows them. But somewhere between the first 2 hours they stop playing a sound even though pstree -p still shows them running.
If I stop both scripts and manually execute them they will run all day until my Kill script runs at 21:30.
Code:
─cron(5502)─┬─cron(4071)───sh(4072)───zmalarm.sh(4073)─┬─grep(4075)
        │            │                                          ├─tail(4074)
        │            │                                          └─zmalarm.sh(4076)
        │            └─cron(6119)───sh(6120)───zmalarm2.sh(6121)─┬─grep(6123)
        │                                                        ├─tail(6122)
        │                                                        └─zmalarm2.sh(6124)
One of the 2 scripts both are the same just the .wave and 1 part of the grep words are different.

Code:
#!/bin/bash
tail -f /var/log/messages | grep --line-buffered 'frontdoor.*Gone into alarm state' | while read line; do aplay /dog1.wav; done

Last edited by Alan87i; 07-12-2011 at 08:25 AM.
 
Old 07-12-2011, 08:50 AM   #8
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
They fork automatically into the background? Is this the same when you execute them interactively or are they bound to the terminal process, i.e. as a kid of the shell and listed with the jobs builtin command? You also logout after you started them?
 
Old 07-12-2011, 09:13 AM   #9
Alan87i
Member
 
Registered: Oct 2005
Location: Quebec
Posts: 119

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Reuti View Post
They fork automatically into the background? Is this the same when you execute them interactively or are they bound to the terminal process, i.e. as a kid of the shell and listed with the jobs builtin command? You also logout after you started them?
System auto logs my user in at boot , never logs out. I control it with vnc most of the time.
If I execute the scripts manually they appear further down the tree on the left side beneath a long list of other jobs with psteee-p other than using that they run in the background.

I used gnome-schedule to setup cron , no output dev/null checked .
I a while ago I killed both tails and changed the start time too 8:36 so both have restarted and are working ATM. It's hard to check because the pstree shows them still running even though the sound stops playing after about 1 hour or more . I have to sit here and manually force alarms to see if the sounds play.
 
Old 07-12-2011, 09:21 AM   #10
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Which process they are bound to - you can get a similar output with
Code:
$ ps -e f -o pid,ppid,command
(f w/o -). Are they bound in both cases to the same process as parent, i.e. the init process?

To investigate what the processes are doing (as you say that they are still listed): you can issue
Code:
$ strace -p pid
to check whether there are any system calls.
 
Old 07-12-2011, 09:57 AM   #11
Alan87i
Member
 
Registered: Oct 2005
Location: Quebec
Posts: 119

Original Poster
Rep: Reputation: 15
Code:
5542  5305  \_ /sbin/dhclient -1 -lf /var/lib/dhcp3/dhclient.eth0.leases -pf /var/run/dhclient.eth0.pid -q -e dhc_dbus
 5326     1 /usr/sbin/hald
 5327  5326  \_ hald-runner
 5340  5327      \_ hald-addon-input: Listening on /dev/input/event3 /dev/input/event2 /dev/input/event5 /dev/input/eve
 5356  5327      \_ hald-addon-acpi: listening on acpid socket /var/run/acpid.socket
 5405  5327      \_ hald-addon-storage: polling /dev/scd0 (every 16 sec)
 5487     1 /usr/sbin/atd
 5502     1 /usr/sbin/cron
19644  5502  \_ /USR/SBIN/CRON
19645 19644  |   \_ /bin/sh -c /home/allan/zmalarm2.sh >/dev/null 2>&1 #JOB_ID_1
19646 19645  |       \_ /bin/bash /home/allan/zmalarm2.sh
19647 19646  |           \_ tail -f /var/log/messages
19648 19646  |           \_ grep --line-buffered 16MM.*Gone into alarm state
19652 19646  |           \_ /bin/bash /home/allan/zmalarm2.sh
19649  5502  \_ /USR/SBIN/CRON
19650 19649      \_ /bin/sh -c /home/allan/zmalarm.sh >/dev/null 2>&1 #JOB_ID_2
19651 19650          \_ /bin/bash /home/allan/zmalarm.sh
19653 19651              \_ tail -f /var/log/messages
19654 19651              \_ grep --line-buffered frontdoor.*Gone into alarm state
19655 19651              \_ /bin/bash /home/allan/zmalarm.sh
 5554     1 /usr/sbin/apache2 -k start
and
Code:
allan@allan-cameras:~$ sudo strace -p 5502
[sudo] password for allan: 
Process 5502 attached - interrupt to quit
restart_syscall(<... resuming interrupted call ...>) = 0
time(NULL)                              = 1310478841
stat64("crontabs", {st_mode=S_IFDIR|S_ISVTX|0730, st_size=4096, ...}) = 0
stat64("/etc/crontab", {st_mode=S_IFREG|0644, st_size=724, ...}) = 0
stat64("/etc/cron.d", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("/etc/cron.d/php5", {st_mode=S_IFREG|0644, st_size=507, ...}) = 0
stat64("/etc/cron.d/anacron", {st_mode=S_IFREG|0644, st_size=244, ...}) = 0
stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=3519, ...}) = 0
time(NULL)                              = 1310478841
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {0x804a680, [CHLD], SA_RESTART}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({60, 0},
This is since I changed cron to start at 8:36 and let it run . Normally I want them to run at 6:30 then at 21:30 this script runs to kill the tail .

Code:
#!/bin/bash
 
pkill -9 tail
 
Old 07-12-2011, 10:29 AM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by Alan87i View Post
It's hard to check because the pstree shows them still running even though the sound stops playing after about 1 hour or more
So the issue is not that they stop running but that they stop playing sound?
 
Old 07-12-2011, 10:41 AM   #13
Alan87i
Member
 
Registered: Oct 2005
Location: Quebec
Posts: 119

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by catkin View Post
So the issue is not that they stop running but that they stop playing sound?
Yes 100 %
When I checked the pstree this morning after noticing the sound stopped all looked normal as I posted above.
So I ran the kill script then changed cron to the time of 8:36 witch was 2 minutes away and they both started again ad have now ran for for just over 2 hours Just checked at 10:40 and both still work fine.
 
Old 07-12-2011, 10:48 AM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Maybe the problem investigation can usefully focus on why the sound-playing parts stop working ...
 
Old 07-12-2011, 11:16 AM   #15
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
What is happening, when you put them into the background? I think you need a helper script, as bash commands and options cannot be put into a cron entry directly. Iím thinking of:
Code:
$ nohup /home/allan/zmalarm2.sh >&/dev/null &
so that they are no longer kids of the cron process.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 09:52 PM
Issues while executing shell scripts through Cron job paragkalra Programming 8 08-02-2008 02:18 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
Cron job and postmap issues TheDude05 Linux - Server 3 08-09-2007 08:13 PM
need help with cron job parthcorp1 Linux - General 2 02-01-2005 12:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 02:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration