• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 109
  • Last Modified:

Schedule set of commands in Linux Program

Dear Experts, how can schedule set of commands in Linux program?

For example: I want to schedule a program called A running at 12.00 AM everyday; but when that A program is running, a set of commands will be executed automatically.

Please suggest.
0
Tjno
Asked:
Tjno
4 Solutions
 
Abhimanyu SuriSr Database EngineerCommented:
Please use CRONTAB , for your reference
 
http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/


Thanks,
Suri
0
 
TjnoNetwork AdministratorAuthor Commented:
Hi, yes I know we have to use crontab to schedule a linux task; but I'm asking for scheduling commands inside a Linux Program. Please read my example
0
 
Sourav ChaterjeeMiddleware Commented:
Hi!
You can use the "at" & "atq" function as well. "batch" command gives you a little more.
Check the link for examples -
https://www.thegeekstuff.com/2010/06/at-atq-atrm-batch-command-examples/
0
 
murugesandinsC C++ Shell script AIX CYGWIN_NT HP-UX Linux MINGW SunOSCommented:
Writing based on your comment:
>> schedule set of commands in Linux program
Assume that "a program called A" => /home/murugesandins/29079531.sh
$ /usr/bin/crontab -e

Open in new window

Add following lines
00 00 *   *   *     /home/murugesandins/29079531.sh
OR:
00 00 *   *   *     /home/murugesandins/29079531.sh additional parameter to 29079531.sh
OR:
00 00 *   *   *     /home/murugesandins/29079531.sh additional parameter to 29079531.sh > /tmp/output.txt 2>/tmp/error.txt
Save and quit
Tested the same using:
56 12 *   *   *     /home/murugesandins/29079531.sh
56 => 56 minutes (IST)
12 => 12 hour (PM)
* => any day of the month (01 to 31)
* => month (01 to 12)
* => Day of the week [ 0 being sunday 1 to 6, 5 being friday :) ]
Sample content of 29079531.sh
$ /bin/cat /home/murugesandins/29079531.sh
#!/bin/ksh
echo "Executing $0 at $(/bin/date)"     >> /tmp/output.txt 2>&1
echo first_command                      >> /tmp/output.txt 2>&1
echo secondcommand                      >> /tmp/output.txt 2>&1
/bin/ls -latr /home                     >> /tmp/output.txt 2>&1

Open in new window


When executing "/usr/bin/crontab -e" for the first time obtained following output:
$ /usr/bin/crontab -e
no crontab for murugesandins - using an empty one

Select an editor.  To change later, run '/usr/bin/select-editor'.
  1. /bin/ed
  2. /bin/nano        <---- easiest
  3. /usr/bin/emacs24
  4. /usr/bin/vim.tiny

Choose 1-4 [2]: 4

Open in new window

If you have selected "/bin/nano"
go to end of that file using down arrow add related minute hour and starts
press Ctrl X
press Y
press Enter

I prefer /usr/bin/vim.tiny instead of /bin/nano => It can be changed using:
$ /usr/bin/select-editor

Select an editor.  To change later, run 'select-editor'.
  1. /bin/ed
  2. /bin/nano        <---- easiest
  3. /usr/bin/emacs24
  4. /usr/bin/vim.tiny

Choose 1-4 [2]: 4

Open in new window

0
 
murugesandinsC C++ Shell script AIX CYGWIN_NT HP-UX Linux MINGW SunOSCommented:
You can change the editor using:
1. /usr/bin/select-editor
OR
echo -n "SELECTED_EDITOR=\"/usr/bin/vim.tiny\"" >  ~/.selected_editor
OR
echo -n  "SELECTED_EDITOR=\"/bin/ed\"" >  ~/.selected_editor
OR
OR
echo -n  "SELECTED_EDITOR=\"/bin/nano\"" >  ~/.selected_editor
OR
echo -n  "SELECTED_EDITOR=\"/usr/bin/emacs24\"" >  ~/.selected_editor

Each option needs to be selected => related user needs to be familiar using related editor (vim/ed/nano/emacs)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now