LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-16-2009, 06:21 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
User cronjob via crontab is hanging


Running Ubuntu 8.10 and have created the following user cronjob that backs up all my data in my home directory:

Code:
#!/bin/bash
# backup data on a daily basis via rsync and a cron job

echo backup started `date` >>/home/cmmiller/backup/backuplog
rsync -avh /home/cmmiller/ /media/Linux_ext3/
echo backup complete `date` >>/home/cmmiller/backup/backuplog
echo du -csh /media/Linux_ext3 | df -h /media/Linux_ext3 >>/home/cmmiller/backup/backuplog
echo
This past weekend I cleaned up my home directory and then deleted all of the files on the external hard drive so it would display the data as it now appears in my home drive.

For some reason after doing this, the cron job now hangs. I can look at top and see various processes running. I kill the processes and the cron job completes.

I ran the cron job for the hell of it from the command line and didn't have the same issue, so I'm not sure what is going on...I am writing to a log to check the progress the next day, however it isn't telling if there is an issue or not.

thanks
 
Old 06-16-2009, 06:36 PM   #2
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
this line confuses me

Code:
echo du -csh /media/Linux_ext3 | df -h /media/Linux_ext3 >>/home/cmmiller/backup/backuplog
can you tell me what you're trying to do here? - it looks broken

maybe you mean:

Code:
du -csh /media/Linux_ext3 >>/home/cmmiller/backup/backuplog
df -h /media/Linux_ext3 >>/home/cmmiller/backup/backuplog
??
 
Old 06-16-2009, 06:43 PM   #3
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Hmmm...That is a pipe, because I want to see in the log on the same line the space used Vs space free...

I can tweak it and have it run overnight and report back the results...

thanks
 
Old 06-16-2009, 06:49 PM   #4
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
well you're piping the string "du -csh /media/Linux_ext3" (not the results of the command, which doesn't really matter because either would be wrong) into 'df', which is meaningless. the result of that is what is getting written to your log.

yes, clean up your script and see if it works better.
 
Old 06-17-2009, 06:25 AM   #5
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Changed the | to ; and its not hanging anymore.

thanks
 
Old 06-17-2009, 09:55 AM   #6
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
here's a helpful trick. you can put your code in a block and redirect the output from the whole block to your log file in one step. that way you don't have to worry about getting all of the redirects in the right place. within the block you can just write script as normal.

Code:
#!/bin/bash
# backup data on a daily basis via rsync and a cron job

{
echo backup started `date`
rsync -avh /home/cmmiller/ /media/Linux_ext3/
echo backup complete `date`
du -csh /media/Linux_ext3
df -h /media/Linux_ext3
echo
} >>/home/cmmiller/backup/backuplog
 
Old 06-17-2009, 06:23 PM   #7
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Cool, didn't know this, thanks for sharing.
 
Old 06-18-2009, 06:21 PM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
you can also do it like so:

Code:
#!/bin/sh

exec > log
exec 2>&1     # errors same place


cat <<EOF
blah
blah
blah
$(date)

EOF
cat flap
or to append of course:
exec >> log

Last edited by bigearsbilly; 06-18-2009 at 06:23 PM.
 
Old 06-18-2009, 09:41 PM   #9
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Thanks for the help, I'm more of a sys admin/network guy...so I only script when there is a need.
 
  


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
[SOLVED] Cronjob: Could not authenticate PAM user ... Authentication failure (for root?!?) JZL240I-U Linux - Security 11 03-14-2019 01:05 PM
How to set up a cronjob as a normal user ? gauthamk Linux - Software 1 09-06-2008 10:01 AM
Single-user not working/hanging player_2 Linux - General 2 08-25-2005 10:16 PM
cronjob entry in crontab rockwell_001 Linux - General 2 06-30-2004 02:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 AM.

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