LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-30-2011, 03:23 AM   #1
sachinsud
Member
 
Registered: Aug 2011
Posts: 38

Rep: Reputation: Disabled
Cron Job- Newbie Here


Hi,

I have a dedicated server which runs on Operating system Mandrake Linux 5.2. This server is located in India. I have another web server which is located in NewYork.

There are some files which gets created on indian server everyday and which i need to move to my newyork server on daily basis.

In order to get this done. i m using this command in indian server.

ncftpput -R -v -u "crazyfre" ftp.dummy.com /public_html/scrim1 /27024/orangebox/cstrike/warmod/

Now i want help in 2 things.

1) First i want to automate this command to get executed everyday at one given time so that i dont have to re run it manually.

2) Once this command is done copying the data i should be able to run another command which deletes the logs from Indian server so that new logs can be created. ( Actually the first command moves the logs )

Thanks for the help
 
Old 08-30-2011, 03:36 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
At first you should read the man pages for the crontab command and the crontab format specifications:
Code:
man crontab
man 5 crontab
then there are plenty of tutorials out there, e.g. http://www.cyberciti.biz/faq/how-do-...-or-unix-oses/. Just a couple of rules to take in mind:

1. The environment of CRON is very limited, the PATH is usually /bin:/usr/bin. For this reason is better to use absolute paths for every command in crontab and in the crontab script. Furthermore, when the cron job is executed it will start operations from the user's home directory, so that it's better to use absolute path even for regular files.

2. To debug a cron job, it's convenient to redirect the standard error and the standard output of the job to a file. If not redirected, the cron daemon sends them to the user's mail.

Try to write down your own crontab and feel free to ask if you encounter some specific problem.
 
Old 08-30-2011, 03:37 AM   #3
sachinsud
Member
 
Registered: Aug 2011
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
At first you should read the man pages for the crontab command and the crontab format specifications:
Code:
man crontab
man 5 crontab
then there are plenty of tutorials out there, e.g. http://www.cyberciti.biz/faq/how-do-...-or-unix-oses/. Just a couple of rules to take in mind:

1. The environment of CRON is very limited, the PATH is usually /bin:/usr/bin. For this reason is better to use absolute paths for every command in crontab and in the crontab script. Furthermore, when the cron job is executed it will start operations from the user's home directory, so that it's better to use absolute path even for regular files.

2. To debug a cron job, it's convenient to redirect the standard error and the standard output of the job to a file. If not redirected, the cron daemon sends them to the user's mail.

Try to write down your own crontab and feel free to ask if you encounter some specific problem.

Thanks a lot!
Let me create a cron job first and then i will share it with you.
Thanks,
 
Old 08-31-2011, 08:57 AM   #4
sandwormusmc
Member
 
Registered: Nov 2006
Distribution: Fedora 15 x86_64
Posts: 76

Rep: Reputation: 24
Quote:
Originally Posted by sachinsud View Post
Hi,

I have a dedicated server which runs on Operating system Mandrake Linux 5.2. This server is located in India. I have another web server which is located in NewYork.

There are some files which gets created on indian server everyday and which i need to move to my newyork server on daily basis.

In order to get this done. i m using this command in indian server.

ncftpput -R -v -u "crazyfre" ftp.dummy.com /public_html/scrim1 /27024/orangebox/cstrike/warmod/

Now i want help in 2 things.

1) First i want to automate this command to get executed everyday at one given time so that i dont have to re run it manually.

2) Once this command is done copying the data i should be able to run another command which deletes the logs from Indian server so that new logs can be created. ( Actually the first command moves the logs )

Thanks for the help
Instead of ncftpput, you can also try rsync with the --delete option. Take a look at the man page for rsync, that may provide an easier way to remove the logs...
 
Old 08-31-2011, 02:30 PM   #5
sachinsud
Member
 
Registered: Aug 2011
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sandwormusmc View Post
Instead of ncftpput, you can also try rsync with the --delete option. Take a look at the man page for rsync, that may provide an easier way to remove the logs...

Thank you the reply.
I tried using this command to use rsync

[root@game1 /]# rsync -az --progress --size-only /27024/orangebox/cstrike/warmod/* ftp.dummy.com:/home/cryfre/public_html/scrim1
ssh: connect to host ftp.dummy.com port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(463) [sender=2.6.8]

I get this error message. Then i spoke to my new year data center guy who provides me the webserver, he told me i dont have ssh putty in my account , neither it can be enabled.

Is there a way i can run the same command without using ssh? If yes, then can someone please modify the same command
1) Without SSH
2) Include that delete option which deletes after the files have been moved.


I am very new to linux servers. Hope fully someone can help.
 
Old 09-01-2011, 02:54 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
rsync can't connect through the FTP protocol, hence you have to stick with some ftp client. I don't know anything about the ncftp tool, but another versatile software is lftp. It comes with the -E option to delete source files after successful transfers. Actually I've never tried this option, anyway it would be safer to keep a backup copy of the original files during your test sessions. The man page of lftp states it's a dangerous option for obvious reasons (indeed any deleting command is potentially dangerous).

I've just looked at the man page of ncftpput: there is a similar option -DD (delete local file after successfully uploading it). If you're more experienced with this tool, you can stick with it. Hope this helps.

Just out of curiosity, did you successfully set up the cron job?
 
Old 09-01-2011, 07:01 AM   #7
sachinsud
Member
 
Registered: Aug 2011
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
rsync can't connect through the FTP protocol, hence you have to stick with some ftp client. I don't know anything about the ncftp tool, but another versatile software is lftp. It comes with the -E option to delete source files after successful transfers. Actually I've never tried this option, anyway it would be safer to keep a backup copy of the original files during your test sessions. The man page of lftp states it's a dangerous option for obvious reasons (indeed any deleting command is potentially dangerous).

I've just looked at the man page of ncftpput: there is a similar option -DD (delete local file after successfully uploading it). If you're more experienced with this tool, you can stick with it. Hope this helps.

Just out of curiosity, did you successfully set up the cron job?
Thank you very much for this -DD option. Now my sync is all set. Though its manual at this point.
But hopefully i will dig more for cron job to schedule it on daily basis.

Nope. i dont have any luck with cron job as such. The reason because when i execute this command it asks fr my ftp password. Which i have to manually put in.

Any suggestions, how can i schedule this command at everyday 4 am + passwords get entered itself.

Thanks
 
Old 09-01-2011, 07:08 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Again looking at the man page, it looks like option -p (lowercase) is what you're looking for. Have you tried it?
 
Old 09-01-2011, 07:56 AM   #9
sachinsud
Member
 
Registered: Aug 2011
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
Again looking at the man page, it looks like option -p (lowercase) is what you're looking for. Have you tried it?

It worked!! Great.. I am such a dumb guy.

Only scheduling this command is left
Any suggestions??
 
Old 09-01-2011, 08:10 AM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Well, suggestions already given in post #2 above. Have you read about the crontab format in
Code:
man 5 crontab
or the link I posted? Something not clear?
 
  


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
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
newbie needing help creating a cron job Lleb_KCir Linux - Software 5 12-13-2004 03:58 PM

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

All times are GMT -5. The time now is 05:53 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