Tanti Technology

My photo
Bangalore, karnataka, India
Multi-platform UNIX systems consultant and administrator in mutualized and virtualized environments I have 4.5+ years experience in AIX system Administration field. This site will be helpful for system administrator in their day to day activities.Your comments on posts are welcome.This blog is all about IBM AIX Unix flavour. This blog will be used by System admins who will be using AIX in their work life. It can also be used for those newbies who want to get certifications in AIX Administration. This blog will be updated frequently to help the system admins and other new learners. DISCLAIMER: Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility. If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.

Friday 22 November 2013

AIX Scheduling

Scheduling: Schedulinghas three types:
1. at
2. cron
3. batch
1. at: Runs commands at a later time.it is a one time scheduling command.
To Schedule Jobs to Run at a Later Time
at [ -c | -k | -s -qQueue] [ -m ] [ -fFile ] { -tDate |Time [ Day ] [ Increment ] }
he atcommand reads from standard input the names of commands to be run at a later time and allows you to specify when the commands should be run.
The at command mails you all output from standard output and standard error for the scheduled commands, unless you redirect that output. It also writes the job number and the scheduled time to standard error.
When the at command is executed, it retains the current process environment. It does not retain open file descriptors, traps, and priority.To schedule a job to run at a later time, you must specify a time to start the job. You may specify the time by using either the -tDate flag or the Time, Day, and Increment parameters. At most, 60 jobs can be scheduled in any given run queue at the granularity of one per second. If more jobs than can be handled are submitted, for every job beyond 60, a file _at is created in /var/spool/cron/atjobs/ which can be safely deleted by the end user.
The Datevariable to the -t flag is specified using the following format:
[[CC]YY]MMDDhhmm[.SS]
The digits in the Date variable are defined as follows:
CCSpecifies the first two digits of the year (the century).
YYSpecifies the second two digits of the year.
MMSpecifies the month of the year (01 through 12).
DDSpecifies the day of the month (01 through 31)./td>
hhSpecifies the hour of the day (00 through 23).
mmSpecifies the minute of the hour (00 through 59).
SSSpecifies the second of the minute (00 through 59).
#atsubmits a job for cron to run at a specific time in the future
(at -f /home/root/bb_at -t 2007122503)
#echo “” | at nowthis starts in the background (and you can log off)
at now +2 mins
#banner hello > /dev/pts/0
(at now + 1 minute,at 5 pm Friday )
#/var/adm/cron/at.denyallows any users except those listed in this file to use the at command.
#/var/adm/cron/at.allowallows only those users listed in this file to use the at command (including root).
#at -lLists at jobs
#atq [user]   Views other user’s jobs (Only root can use this command.)
#at -r   Cancels an at job
#atrm job  Cancels an at job by job number
#atrm userCancels an at job by the user (root can use it for any user; users can cancel their jobs.)
#atrmCancels all at jobs belonging to the user invoking the atrm command
e.g
To schedule the command from the terminal, enter a command similar to one of the following:
If sysadmin is in your current directory, enter:
at 5 pm Friday
sysadmin

If sysadmin is in $HOME/bin/sysadmin, enter:
at now + 2 days
$HOME/bin/sysadmin
Note:
When entering a command name as the last item on the command line, a full path name must be given if the command is not in the current directory, and the at command will not accept any arguments.
2. Crontab:Submits, edits, lists, or removes cron jobs.
crontab [-e [UserName] | -l [UserName] | -r [UserName] | -v[UserName] | File ]

The crontab command submits, edits, lists, or removes cron jobs. A cron job is a command run by the cron daemon at regularly scheduled intervals. To submit a cron job, specify the crontab command with the -e flag. The crontabcommand invokes an editing session that allows you to create a crontab file. You create entries for each cron job in this file. Each entry must be in a form acceptable to the cron daemon. For information on creating entries, see The crontab File Entry Format.
Security
Only the root user or the owner of the crontab file can use UserName following the -e-l,-r, and x-small;”>-v flags to edit, list, remove, or verify the crontab file of the specified user.
Controls on Using the crontab Command
/var/adm/cron/cron.allow           File containing users who allowed cron service
/var/adm/cron/cron.deny             File containing users denied cron service
/var/adm/cron/at.allow                File containing users who allowed at service
/var/adm/cron/at.deny                   File containing users denied at service
# crontab –e                                   This command will open Vi editor and after making changes user can save and quit.
# crontab –l                                       Command will list all the jobs scheduled.
# crontab –r                                 this command will remove all the cron jobs. You should be very careful in running these commands in production environment.
 The crontab File Entry Format
crontab file contains entries for each cron job. Entries are separated by newline characters. Each crontab file entry contains six fields separated by spaces or tabs in the following form:
minute hour day_of_month month weekday command
These fields accept the following values:
minute0 through 59
hour0 through 23
day_of_month1 through 31
month1 through 12
weekday0 through 6 for Sunday through Saturday
commanda shell command
e.gSep 1 12:30 AM is represented as:
30           00           1              9              *
  • To write the time to the console every hour on the hour, enter:
0 * * * * echo The hour is `date` .
>/dev/console
  • To run the calendar command at 6:30 a.m. every Monday, Wednesday, and Friday, enter:
30 6 * * 1,3,5 /usr/bin/calendar
3. batch: Runs jobs when the system load level permits.i.e system is average.
Batch
The batch command reads from standard input the names of commands to be run at a later time and runs the jobs when the system load level permits. The batch command mails you all output from standard output and standard error for the scheduled commands, unless you redirect that output. It also writes the job number and the scheduled time to standard error.
When thebatch command is executed, it retains variables in the shell environment, and the current directory; however, it does not retain open file descriptors, traps, and priority.
The batch command is equivalent to entering the at -q b -m now command. The -q b flag specifies the at queue for batch jobs.
Examples
To run a job when the system load permits, enter:
batch <<!
longjob
!This example shows the use of a “Here Document” to send standard input to the batch command.

Files

/usr/bin/batchContains the batchcommand.
/bin/batchSymbolic link to the batch command.
/var/adm/cronIndicates the main crondaemon directory.
/var/spool/cron/atjobsIndicates the spool area.

No comments:

Post a Comment