LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-16-2011, 06:51 AM   #1
Raju Roy
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Rep: Reputation: Disabled
Question How to Schedule a task in RHEL?


I want to schedule a shell(.sh) script. Please tell me the command or procedure.
 
Old 09-16-2011, 07:07 AM   #2
tonyr-bos
LQ Newbie
 
Registered: Sep 2011
Posts: 2

Rep: Reputation: Disabled
"at" or "cron"

"at" is good for one-time scheduling, "cron" is good for regular scheduling.
 
Old 09-16-2011, 08:23 AM   #3
vukomir
LQ Newbie
 
Registered: Apr 2011
Location: Romania, Timisoara
Posts: 3

Rep: Reputation: 0
To see what crontabs are currently running on your system, you can open a terminal and run:

sudo crontab -l

To edit the list of cronjobs you can run:

sudo crontab -e

ex:
* * * * * /bin/execute/this/script.sh

As you can see there are 5 stars. The stars represent different date parts in the following order:

minute (from 0 to 59)
hour (from 0 to 23)
day of month (from 1 to 31)
month (from 1 to 12)
day of week (from 0 to 6) (0=Sunday)
 
Old 09-16-2011, 08:34 AM   #4
tonyr-bos
LQ Newbie
 
Registered: Sep 2011
Posts: 2

Rep: Reputation: Disabled
crontab

one addition to vukomir's response: each user has a crontab. so, doing
sudo crontab -l
will show you root's crontab. you can also have your own crontab if you want.
 
1 members found this post helpful.
Old 09-17-2011, 05:33 AM   #5
Raju Roy
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you, But?

Quote:
Originally Posted by vukomir View Post
To see what crontabs are currently running on your system, you can open a terminal and run:

sudo crontab -l

To edit the list of cronjobs you can run:

sudo crontab -e

ex:
* * * * * /bin/execute/this/script.sh

As you can see there are 5 stars. The stars represent different date parts in the following order:

minute (from 0 to 59)
hour (from 0 to 23)
day of month (from 1 to 31)
month (from 1 to 12)
day of week (from 0 to 6) (0=Sunday)
Hi, thank you very much to all of you for you helping hands, however, now there is a problem is case of ftp command, it is not working i.e. I want to backup(copy) my Oracle .dmp files from my Sun Solaris Server to RHEL Server I wrote the following codes in a .sh file:

ftp 192.9.1.33
backup
backup
cd /data3/export/hpcl
lcd /data3/Bropts_dbk
prompt
bin
hash
mget *.dmp
bye
exit 0


and I want to schedule my backup. How is it possible!!!!

Regards
 
Old 09-17-2011, 02:02 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Raju Roy View Post
Hi, thank you very much to all of you for you helping hands, however, now there is a problem is case of ftp command, it is not working i.e. I want to backup(copy) my Oracle .dmp files from my Sun Solaris Server to RHEL Server I wrote the following codes in a .sh file:
Code:
ftp 192.9.1.33
backup
backup
cd /data3/export/hpcl
lcd /data3/Bropts_dbk
prompt
bin
hash
mget *.dmp
bye
exit 0
and I want to schedule my backup. How is it possible!!!!
Well, those 'codes' aren't going to work. Have you tried to run that from a command-line first??? Unless your script can work from the command line, it won't work through cron. So fix that first..a hint, here: look at expect, since your script (as written above) will fail on line 2, because as soon as it forks into the FTP command, processing of the SHELL SCRIPT will stop. So, your user ID/password won't get written, other commands won't work, etc. Expect can automate this task, but again, test the script from the command line first.

Aside from that, read the man page on cron/crontab, and you can see how to automate a script easily. Google has lots of examples, if you look:
http://www.pantz.org/software/cron/croninfo.html

On an related note...FTP isn't the best tool to use for the job anymore. SCP or SFTP are more secure, and support key-exchange logins, meaning you don't need to supply a password, which makes things easy to script.
 
Old 09-19-2011, 01:22 AM   #7
Raju Roy
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Well, those 'codes' aren't going to work. Have you tried to run that from a command-line first??? Unless your script can work from the command line, it won't work through cron. So fix that first..a hint, here: look at expect, since your script (as written above) will fail on line 2, because as soon as it forks into the FTP command, processing of the SHELL SCRIPT will stop. So, your user ID/password won't get written, other commands won't work, etc. Expect can automate this task, but again, test the script from the command line first.

Aside from that, read the man page on cron/crontab, and you can see how to automate a script easily. Google has lots of examples, if you look:
http://www.pantz.org/software/cron/croninfo.html

On an related note...FTP isn't the best tool to use for the job anymore. SCP or SFTP are more secure, and support key-exchange logins, meaning you don't need to supply a password, which makes things easy to script.

Well you are right, it is failing in command line. Can you give me an example of SFTP command for transferring my data from one server to other, as shown in my ftp code you can understand what I wanted to do. So please help me as I am not familiar with SFTP.
 
Old 09-19-2011, 09:42 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Raju Roy View Post
Well you are right, it is failing in command line. Can you give me an example of SFTP command for transferring my data from one server to other, as shown in my ftp code you can understand what I wanted to do. So please help me as I am not familiar with SFTP.
Then the best thing you can do is to read the man page for it, since it'll explain how to use it.

A simple command-line is
Code:
sftp <user id>@<ip address of remote machine>
but again, SCP is also an option, and easier to script for:
Code:
scp <user ID>@<remote address>:/remote/path/*.dmp /path/on/local/machine/
If you have your keys swapped, you won't need to put in a password, and this will easily run automatically. One catch is that you will need to either run this in a USER crontab (not roots), or specify a users identification on the command line, if you do run it under root's crontab.
 
  


Reply



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
RHEL 5.5 Schedule updates mhouston100 Linux - Server 4 07-09-2010 04:50 AM
How to schedule for a repeated task? hadimotamedi Linux - Newbie 7 05-04-2010 02:58 AM
shut down time in schedule task fa_khan50 Linux - Server 3 02-08-2008 11:09 AM
How to schedule *interactive* task with at or cron fast_rizwaan Linux - Newbie 4 09-09-2005 06:26 PM
Schedule a task ! L1nuxbug Linux - Networking 4 03-02-2005 07:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:59 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
Open Source Consulting | Domain Registration