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.
LVL 5
DP230Network AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Abhimanyu SuriDatabase EngineerCommented:
Please use CRONTAB , for your reference
 
http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/


Thanks,
Suri
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DP230Network 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
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
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
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.