Sponsored Content
Top Forums Shell Programming and Scripting Script that will look the same as Cron Post 303037677 by drysdalk on Friday 9th of August 2019 10:24:12 AM
Old 08-09-2019
Hi,

In that case, you'd really be into the territory of literally re-inventing crontab. For example, you could define an input file format that consisted of runtimes and their associated commands, and have your script read that file and run the commands when the runtimes arrived - in other words, to do pretty much exactly what the crond daemon does.

I've not got time right now to write a full example unfortunately, but if you defined your input format as something like:

Code:
Mon,10,00,/usr/local/bin/foo.sh
Fri,17,00,/usr/local/bin/bar.sh

and had your script read this file line-by-line, breaking out the variables in each line into the days, hour, minutes and commands, you could then run those commands via the same kind of infinite-loop approach as you've seen in the examples given thus far.

If you absolutely don't have access to crontab, and can't get the maintainer of the server to put in the cron entries for you, then this would more or less be the only way you'd get a general-purpose task scheduler going. But you'd probably want to be sure that the maintainer of the server was happy with you doing this, since presumably they've blocked access to cron to prevent people running commands on a set schedule, which is what you'd end up doing anyway here.
This User Gave Thanks to drysdalk For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron Script Q

When logged in as root if I type "env" there are a bunch of environment settings including one for CLASSPATH. However, I ran a cron script that ran this command "env > cronEnv". I noticed that the environment variables were entirely different inside the script. There wasn't even a CLASSPATH... (2 Replies)
Discussion started by: doublek321
2 Replies

2. UNIX for Dummies Questions & Answers

Cron + Script = No Output?

I've got an *extremely* simple script I want to run every minute: #!/bin/sh ping -c 1 192.168.1.20 > ~/onlinestatus.txt So, the script is called "status", it's executable, and in the correct path, etc. In a terminal window (I'm using Mac OS X), I can type status, and it will create... (4 Replies)
Discussion started by: jmf77
4 Replies

3. AIX

problem with a script and the cron

hello I use a script to give me the number of users, at each hour. this script read a file where there is the number of users for each hour and for each month (so 12 files per year). If i execute the script (root), it is ok, i have xxx users for each hour. if I put the script in the cron... (1 Reply)
Discussion started by: pascalbout
1 Replies

4. Shell Programming and Scripting

script not working in CRON

guys i have written a very simple script .it runs manually well. but when i put it in cron,it doesn't give the desired output. script looks like this: #! /usr/bin/sh #script for loading data in table using ctl file/Abhijeet K/08.07.2006 /svm_wl1/. .profile cd... (5 Replies)
Discussion started by: abhijeetkul
5 Replies

5. Solaris

Need to cron the script

I want to cron one script which should run every second Thursday (in general Nth occurence of any day) of every month. I am not getting the exact idea of doing this; Please guide. Regards, (3 Replies)
Discussion started by: jaiankur
3 Replies

6. Shell Programming and Scripting

how to run script? call other script? su to another user? make a cron?

Good morning. I am searching for "how-to"'s for some particular questions: 1. How to write a script in HP-UX 11. 2. How to schedule a script. 3. How to "call" scripts from the original script. 4. How to su to another user from within a script. This is the basics of what the... (15 Replies)
Discussion started by: instant000
15 Replies

7. Solaris

Script for cron

Dear All, I have an assignment about collecting /var/adm/messages on each server running Solaris 9. All these servers will be installed with a script that collect all the messages in cron. All the messages will be collected by a single server. I have a script to collect all the messages, but... (2 Replies)
Discussion started by: frankoko
2 Replies

8. Shell Programming and Scripting

cron a script

This has to be the ultimate newbie question... I have a script that works well. To run it, I cut and paste it into a putty session. Is there a way to put the script into a file and just run that file -- like a DOS batch file? I'd like to schedule the file to run daily. Thanks,... (3 Replies)
Discussion started by: landog
3 Replies

9. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

10. Shell Programming and Scripting

Script in cron

I have a script that require input from terminal at some point (either a,b or c) How can I cron the script and automatically assume c as the input. (2 Replies)
Discussion started by: aydj
2 Replies
CRON(8) 						      System Manager's Manual							   CRON(8)

NAME
cron - daemon to execute scheduled commands (Vixie Cron) SYNOPSIS
cron [-f] [-l] [-L loglevel] DESCRIPTION
cron is started automatically from /etc/init.d on entering multi-user runlevels. OPTIONS
-f Stay in foreground mode, don't daemonize. -l Enable LSB compliant names for /etc/cron.d files -L loglevel Sets the loglevel for cron. The standard logging level (1) will log the start of all the cron jobs. A higher loglevel (2) will cause cron to log also the end of all cronjobs, which can be useful to audit the behaviour of tasks run by cron. Logging will be disabled if the loglevel is set to zero (0). NOTES
cron searches its spool area (/var/spool/cron/crontabs) for crontab files (which are named after accounts in /etc/passwd); crontabs found are loaded into memory. Note that crontabs in this directory should not be accessed directly - the crontab command should be used to access and update them. cron also reads /etc/crontab, which is in a slightly different format (see crontab(5)). Additionally, cron reads the files in /etc/cron.d: it treats the files in /etc/cron.d as in the same way as the /etc/crontab file (they follow the special format of that file, i.e. they include the user field). However, they are independent of /etc/crontab: they do not, for example, inherit environment variable settings from it. The intended purpose of this feature is to allow packages that require finer control of their scheduling than the /etc/cron.{daily,weekly,monthly} directories to add a crontab file to /etc/cron.d. Such files should be named after the package that sup- plies them. Files must conform to the same naming convention as used by run-parts(8): they must consist solely of upper- and lower-case letters, digits, underscores, and hyphens. If the -l option is specified, then they must conform to the LSB namespace specification, exactly as in the --lsbsysinit option in run-parts. Like /etc/crontab, the files in the /etc/cron.d directory are monitored for changes. In general, the admin should not use /etc/cron.d/, but use the standard system crontab /etc/crontab. In contrast to the spool area, files in /etc/cron.d may be symlinks, provided that both the symlink and the file it points to are owned by root. cron then wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute. When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists). The children copies of cron running these processes have their name coerced to uppercase, as will be seen in the syslog and ps output. Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on /etc/crontab) has changed, and if it has, cron will then examine the modtime on all crontabs and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note that the crontab(1) command updates the modtime of the spool directory whenever it changes a crontab. Special considerations exist when the clock is changed by less than 3 hours, for example at the beginning and end of daylight savings time. If the time has moved forwards, those jobs which would have run in the time that was skipped will be run soon after the change. Con- versely, if the time has moved backwards by less than 3 hours, those jobs that fall into the repeated time will not be re-run. Only jobs that run at a particular time (not specified as @hourly, nor with '*' in the hour or minute specifier) are affected. Jobs which are specified with wildcards are run based on the new time immediately. Clock changes of more than 3 hours are considered to be corrections to the clock, and the new time is used immediately. cron logs its action to the syslog facility 'cron', and logging may be controlled using the standard syslogd(8) facility. ENVIRONMENT
If configured in /etc/default/cron in Debian systems, the cron daemon localisation settings environment can be managed through the use of /etc/environment or through the use of /etc/default/locale with values from the latter overriding values from the former. These files are read and they will be used to setup the LANG, LC_ALL, and LC_CTYPE environment variables. These variables are then used to set the charset of mails, which defaults to 'C'. This does NOT affect the environment of tasks running under cron. For more information on how to modify the environment of tasks, consult crontab(5). The daemon will use, if present, the definition from /etc/timezone for the timezone. The environment can be redefined in user's crontab definitions but cron will only handle tasks in a single timezone. SEE ALSO
crontab(1), crontab(5) AUTHOR
Paul Vixie <paul@vix.com> 4th Berkeley Distribution 19 April 2010 CRON(8)
All times are GMT -4. The time now is 06:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy