The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Linux Shell Question: how to print the shell script name ? meili100 UNIX for Dummies Questions & Answers 3 07-01-2008 02:55 PM
question about about Shell programming thungmail Shell Programming and Scripting 1 04-01-2008 02:40 PM
shell question convenientstore Shell Programming and Scripting 2 06-03-2007 06:05 PM
#!/bin/sh shell question GCTEII Shell Programming and Scripting 0 02-23-2006 03:08 AM
Shell question anjanb2 UNIX for Dummies Questions & Answers 5 07-03-2002 01:00 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2009
dswz dswz is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 2
Shell Question

Hi All,

I am having this problem and I can't find a decent answer anywere.
I'am trying to perform multiple command in a shell script.

For example

Code:
mkdir test
tar cvzf test.tar.gz test/
rmdir test

The problem I get is that if I run this file as a cronjob, with a big "test" folder; the rmdir is making targz incomplete.

I've been using the sleep command to stretch the amount of time so that the tar command has time enhough to finish, but I would like to make it more flexible.

What is the best way to do this.. I know the "command1 && command2" option but the backupscript I am trying to make is multiline..
Also tried:


Code:
command1 &
command2 &
command3

I am a shell beginner, but not a beginning programmer..

Any help appreciated. I will post my code if someone's interested.

Daniel
  #2 (permalink)  
Old 06-30-2009
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,245
The easiest and best way is to put your commands in a script and call that from your crontab.
  #3 (permalink)  
Old 06-30-2009
dswz dswz is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 2
Thanks, reborg, for you quick reply,

I think I wasn't clear enough.

This is the code I wrote:


Code:
#!/bin/sh
HOME=/home/mvo
PATH=/home/mvo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

echo -------------------------------------------- >> /home/mvo/backuplog
echo Backup Started `date` >> /home/mvo/backuplog
cd /

if [ -d /home/backups/`date +%w`/ ] ; then
   rm /home/backups/`date +%w`/backup.tar.gz
   echo Overwriting Day `date +%w` starting now.. >> /home/mvo/backuplog
else
   mkdir /home/backups/`date +%w`/
fi

mkdir /home/backups/tmp
mysqldump -u Username -pPassword Databasename | gzip > /home/backups/tmp/mysqldump.sql.dump.gz
echo Database Backup Complete.. >> /home/mvo/backuplog

cp -Rf /var/www /home/backups/tmp
cp -Rf /home/groupoffice /home/backups/tmp
tar czvf /home/backups/`date +%w`/backup.tar.gz /home/backups/tmp
rm -Rf /home/backups/tmp
echo GroupOffice Backup Complete.. >> /home/mvo/backuplog

echo Backup Completed `date` >> /home/mvo/backuplog

And it is a cronjob. However when I run this script ./backup.sh then everything works fine.. When I run it through a cronjob the "rm -Rf /home/backups/tmp" and the "cp -Rf /var/www /home/backups/tmp" commands are like "overwritten" by the next commands.. in other words: they start to early aka they wont wait for previous command to finish.

How can I get past this? I've tried sleep but I want to keep my script flexibel as the content of the backupdirs may change in size.
So what I want to do is wait for a command to finish before calling a next command!

Thanks for you help!

Last edited by dswz; 06-30-2009 at 09:18 PM..
  #4 (permalink)  
Old 07-01-2009
jp2542a jp2542a is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 142
Try the builtin wait command...

Perhaps a sequence like:

Some-command &
wait $!
  #5 (permalink)  
Old 07-02-2009
laurentv laurentv is offline
Registered User
  
 

Join Date: Mar 2009
Location: Montreal, Canada
Posts: 33
did you check your mail for any message from cron ?
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0