LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-19-2013, 08:32 PM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 359

Rep: Reputation: 0
Angry alternative approach for cron job


The fools have disabled cron job creation and scheduling access so is there any way I can create and scedule a job on unix server (linux Red hat)?

Please assist me here.

Thank you.
 
Old 03-19-2013, 08:46 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Basically write a simple daemon (basically an infinite loop) that detaches thus
Code:
nohup mydaemon >mydaemon.log 2>&1 &
The fiddly bit is the timing; getting it to run eg on average once an hour just involves a sleep(60 mins) call at the bottom of the loop (syntax is programming lang dependent).
Getting it to run at a specific time eg once an hr at say 5 mins past the hr requires some fiddly work to avoid hammering the system with time check cmds.
Easiest may be to calc the next run time after the current processing completes, then use an alarm() (internal/library call to SIGALRM() ) call to wait without polling the system clock continuously.
 
Old 03-19-2013, 10:26 PM   #3
sysmicuser
Member
 
Registered: Mar 2010
Posts: 359

Original Poster
Rep: Reputation: 0
I did a very simple stuff

nohup <scrip> &

It runs but when I do exit from unix terminal it exits, why?

I did nohup and running in background so why it should give up?
 
Old 03-19-2013, 10:50 PM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
You could try at command (see manual here), which's not an alternative to cron scheduling, but runs a specific job at mentioned time.

Basic syntax is:
Code:
~$ at <time>
~$ at <time> < FILE
 
Old 03-19-2013, 11:19 PM   #5
donls
LQ Newbie
 
Registered: May 2010
Posts: 10
Blog Entries: 1

Rep: Reputation: 0
I did a Google search for 'disable nohup' and got some interesting hits. First, there are several other constructs for which nohup is syntactic sugar - it is asserted by many posters that it is impossible to disable nohup, since you can choose one of the other methods.

My response to this is: have you checked whether nohup has been replaced by an alias, a function, or a dummy program? Seems to me like that might cause enough confusion for some people to give up; the ones "they" are interested in dissuading are not likely to be stopped.

Besides nohup, I also saw references to screen and disown - is either of these installed?

Screen is handy (if available) because you can start a command running, detach from it, then come back later to the same output screen.

One suggestion was that some processes don't like to run when they lose the terminal. For this, something like screen is likely to be required. Several other posts indicated that nohup had stopped working when HPUX was upgraded.

The disown command also sounds handy - converts process into a daemon.

Check the results of that Google query, most of the first page. Some respondents have some pretty helpful ideas, and [at least] one might be the solution you seek.

Finally, let us know what you find out!
 
Old 03-19-2013, 11:20 PM   #6
sysmicuser
Member
 
Registered: Mar 2010
Posts: 359

Original Poster
Rep: Reputation: 0
@shivaa

Unfortunately I do not have permission to run at
 
Old 03-19-2013, 11:23 PM   #7
donls
LQ Newbie
 
Registered: May 2010
Posts: 10
Blog Entries: 1

Rep: Reputation: 0
Quote:
Originally Posted by sysmicuser View Post
@shivaa

Unfortunately I do not have permission to run at
Yes, that would seem to go along with disallowing cron.

Another solution (one we used on my first big process, where I was not allowed to cron) was to have a process on another system connect to the host and issue the command.

Of course, you would need some variation of nohup for this to work... (we were at least allowed nohup!).
 
Old 03-19-2013, 11:34 PM   #8
sysmicuser
Member
 
Registered: Mar 2010
Posts: 359

Original Poster
Rep: Reputation: 0
@donls

Thanks for your input. My mistake I ran nohup without programming the script to run as a indefinite loop. Rectified and now it works.

All I want now is the start time @ 12.00 am and then script would wait (sleep 86400) and then again run it. Not sure how to get that timing. Also chism01 suggested that this is poor way (sleep command) as it could result in performance degradation and suggested to use gettimer() so need to explore that part.

I will keep posted if I get anything that starts running.
 
Old 03-20-2013, 12:03 AM   #9
donls
LQ Newbie
 
Registered: May 2010
Posts: 10
Blog Entries: 1

Rep: Reputation: 0
Wink Those who forget history are condemned...

Quote:
Originally Posted by sysmicuser View Post
Thanks for your input. My mistake I ran nohup without programming the script to run as a indefinite loop. Rectified and now it works.
doh!

I can't remember how many times that has happened to me...

Of course, that's a problem; as long as I keep forgetting that tiny detail, I keep repeating it!

At least, having done it n times, it's much easier to find & correct the n+1 time.
 
Old 03-20-2013, 12:24 AM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Actually, sleep() is low overhead... I was referring to the process of 'resetting' the next run, due to the fact that each process run takes a finite amt of time, so each sleep(86400) would cause the next run to be 1hr+prev_process_secs into the future ie time creep...

EG if processing takes 5mins (300 secs), the next run (naively coded) would be 86400+300, the one after that would be 86400+300+300 etc relative to 1st run time.

What you'd do is check the time (once) immediately after the processing and sleep(86400 - processing_time_secs).
(In retrospect, this is saner than using SIGALARM, but you should probably test both briefly).

Re 'at' : I assumed disabling cron would mean they've disabled 'at' as well, that's why I didn't mention it.
 
Old 03-20-2013, 09:49 AM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Quote:
Originally Posted by chrism01 View Post
Actually, sleep() is low overhead... I was referring to the process of 'resetting' the next run, due to the fact that each process run takes a finite amt of time, so each sleep(86400) would cause the next run to be 1hr+prev_process_secs into the future ie time creep...

EG if processing takes 5mins (300 secs), the next run (naively coded) would be 86400+300, the one after that would be 86400+300+300 etc relative to 1st run time.

What you'd do is check the time (once) immediately after the processing and sleep(86400 - processing_time_secs).
(In retrospect, this is saner than using SIGALARM, but you should probably test both briefly).

Re 'at' : I assumed disabling cron would mean they've disabled 'at' as well, that's why I didn't mention it.
One way to work around that is to use a script like:

Code:
while 1 do
   <script to be run> &
   sleep 86400
done
This way you put the actual script to be run in background (which takes very little time - under a tenth of a second), and then sleep for the given number of seconds.

Since the sleep time is limited to seconds, the tenth fraction is below the resolution of the clock (working in seconds), that the delay disappears.
 
Old 03-22-2013, 09:12 AM   #12
sysmicuser
Member
 
Registered: Mar 2010
Posts: 359

Original Poster
Rep: Reputation: 0
Guys,

I have a very quick and interesting question for you. Does a sleep 86400 induce high memory usage on unix server?
 
Old 03-22-2013, 10:52 AM   #13
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,711

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Only that used by the shell process itself.

For the most part, once the shell goes to sleep it can be nearly completely paged out. The executable portions dropped entirely (reloaded from the executable on disk), most of the data pages go into swap.

But since the executable portion is very likely used by other processes, even the executable may stay in memory (these are shared pages), so only a few data pages would remain.
 
  


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
Debian daily cron job won't run, but does run in cron.hourly. sandersch Linux - General 7 05-24-2012 02:50 AM
how to abort cron if the previous cron job not yet finished? Winanjaya Linux - Newbie 2 05-22-2012 07:44 PM
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 09:52 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 imanahmadi Linux - Newbie 1 07-04-2003 12:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:14 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration