LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-16-2009, 05:07 PM   #1
sebasg91
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Rep: Reputation: Disabled
Cron + task timing / order


Hi guys,

I've been doing my research, however I couldn't find the answer.

I created a file which basically copy a full directory (700Mb approx.),
then I put all together with tar, compress with gzip, and finally I erase the temporary directory.

I am trying to do all together in a file, but it seems to start with the 2nd operation before finishing the first one. Therefore, sometimes I have partials .tar, unreadable .gz, etc.

Does is make sense? Is there some kind of pause I can use in between commands? Should I create 3 / 4 different enters in the cron tab?
This last option of course that would work, yet doesn't seems to me the better way to do it.

Thanks
Sebas.
 
Old 11-16-2009, 05:25 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Post your file and cron entries.
 
Old 11-16-2009, 05:27 PM   #3
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
How about requiring the first set of commands to finish before executing the second?

cp /home/blah /tmp/blah && tar cfvz /backup/`date +%Y%m%d`.tgz /tmp/blah && rm -Rf /tmp/blah
 
Old 11-16-2009, 08:27 PM   #4
sebasg91
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks guys! I don't have my files right here (they are at work).

I'll try it tomorrow and let you know.

I think that rweaver's idea will definitely work!

Cheers,
Sebastian
 
Old 11-19-2009, 06:14 PM   #5
sebasg91
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi guys, it's me again... I'm going insane with this, sthing really wired (unless too me) is happening.


This is my crontab so far:
# m h dom mon dow command
0 2 * * * /home/lager/backups/capitalBackUp


Then, this is capitalBackUp executable file:
today=$(date +%Y%m%d)

mkdir /home/lager/backups/$today && mkdir /home/lager/backups/$today/tmp && cp -R /home/lager/applications/capital/* /home/lager/backups/$today/tmp && tar cvfz /home/lager/backups/$today/capital.tar /home/lager/backups/$today/tmp && gzip -9 /home/lager/backups/$today/capital.tar && rm -Rf /home/lager/backups/$today/tmp


Then it turns that if I run the file by myself, I get as result the file capital.gz (~=100Mb), BUT if the file is run by cron, I get as final result a file capital.tar (=9.1Mb --> always same size) and all the files in the directory TMP.

Does it make any sense? Some reasonable explanation?

I hope you can help, coz I have no clue!

Thanks!
Sebas.
 
Old 11-20-2009, 02:14 PM   #6
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by sebasg91 View Post
today=$(date +%Y%m%d)

mkdir /home/lager/backups/$today && mkdir /home/lager/backups/$today/tmp && cp -R /home/lager/applications/capital/* /home/lager/backups/$today/tmp && tar cvfz /home/lager/backups/$today/capital.tar /home/lager/backups/$today/tmp && gzip -9 /home/lager/backups/$today/capital.tar && rm -Rf /home/lager/backups/$today/tmp
Try this:

Code:
#!/bin/bash
today=$(date +%Y%m%d)

mkdir -p /home/lager/backups/$today
tar cf /home/lager/backups/$today/capital.tar /home/lager/applications/capital/*
gzip -9 /home/lager/backups/$today/capital.tar
 
  


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
Cron Timing Murdock1979 Linux - Server 4 09-27-2011 04:02 PM
Cron.daily timing info (problem and solution) dannystaple SUSE / openSUSE 5 08-06-2008 07:31 AM
How To Create A Cron Tab/Task? Harpo Linux - Newbie 4 01-07-2007 01:36 PM
Cron Job Selective Timing kyosuke Linux - General 3 03-01-2006 09:52 PM
[cron][mdk9.1]cron deamon seems to ignore some task... yannrichet Linux - Newbie 5 06-26-2003 09:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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