LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-24-2013, 06:37 AM   #16
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285

Did you once try as said in post #10 above?
 
Old 02-24-2013, 06:40 AM   #17
Mainer44
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
I did try that both ways and that had no effect. When I used ls to see the directory's contents, it was empty.
 
Old 02-24-2013, 06:53 AM   #18
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Alright. Well, I am asking just because sometimes everything looks ok in crontab, but still it do not generate desired results. I don't know how cron's source code and cache mechanism works. But sometimes it behaves weirdly.
 
Old 02-24-2013, 07:24 AM   #19
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,470
Blog Entries: 54

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Quote:
Originally Posted by Mainer44 View Post
I'm not totally sure what happened, but
...and since you never posted contents of '/home/username/cron/mycron' we will never know either.


Quote:
Originally Posted by Mainer44 View Post
what I do know is that I can put the cron table in my home directory and I can tell cron where to find it with the crontab command and relative path.
I think you're confusing things. Most of the posts in this thread have been about common cron job and crontab entry-related errors while your post about 'mkdir /home/username/cron' in essence is about loading a complete crontab file: a crontab file to be loaded with 'crontab /path/to/file' can reside anywhere it can be read.


Quote:
Originally Posted by Mainer44 View Post
Is there a standard location to put scripts? Mine was in my home directory as was my crontab as well as both files involved in the backup.
No. Script location does not matter as long as the users shell can execute it.


Quote:
Originally Posted by Mainer44 View Post
I still don't understand why using the crontab -e and absolute path didn't work.
First of all if cron encounters an error then it will fire off an email to the crontab owner (unless the MAILTO variable is unset). So it's always good to check your email before anything else.
Secondly it may be more efficient to make applications and shell scripts emit verbose or debug information while testing. The Cron daemon itself allows for setting "-x" (though that's rarely needed as /var/log/cron or equivalent will show job execution or not), for rsync the OP already included "-v" and a shell like BASH can be run like "#!/bin/bash -vx".
Finally it may be preferable to test script or application functionality with non-destructive commands. Like a lot of applications rsync has a "--dry-run" switch so using "-nv" (or using the log file option) could have helped to determine if the problem was with rsync or not.
 
1 members found this post helpful.
Old 02-24-2013, 08:33 AM   #20
Mainer44
LQ Newbie
 
Registered: Feb 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thank you unSpawn,

As to not posting the contents of '/home/username/cron/mycron' my apologies. I thought I had in the original posting, but now that I reread that I realize that I did not. In fact I changed it to what shivaa suggested, namely '* * * * * bash /home/username/bin/backup.sh'.

Regarding using the common crontab entry method, that was the only way I knew of to create and activate a crontab until yesterday when I happened upon the aforementioned book "Unix Power Tools", page 494.

Sadly despite lots of searching I was unable to locate any logs that were helpful. I tried to find the directories and files that were suggested and couldn't find them or figure out how to read them. I did not activate the MAILTO option. Linux is brand new to me and I seem to be facing a steep learning curve.

I am brand new to scripting also. Although I did not explain it, I did make the script by itself first. Then I figured out how to run it from the command line before I tried to have the cron daemon run it. Up to that point I was fine, everything ran as I had expected. My trouble was having cron automate the process. I am struggling to understand and navigate the filesystem. What I don't understand is the point of view of the crontab entry command. In other words, when one uses the command 'crontab -e' is that saved in the users home directory or in the root directory? In either case, isn't '/home/username/bin/backup.sh' the absolute path that can be accessed from anywhere in the filesystem?

I have never heard of any switches or options in the shebang statement. I originally did have the verbose switch in the rsync command when I ran it from the command line, but once I had the cron daemon activate the command I felt it was unnecessary since it wouldn't be written to standard output, e.g. the screen.
 
Old 02-24-2013, 09:29 AM   #21
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,470
Blog Entries: 54

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Quote:
Originally Posted by Mainer44 View Post
As to not posting the contents of '/home/username/cron/mycron' my apologies. I thought I had in the original posting, but now that I reread that I realize that I did not. In fact I changed it to what shivaa suggested, namely '* * * * * bash /home/username/bin/backup.sh'.
OK. shivaa actually posted '15 * * * * "bash /home/username/bin/backup.sh"' which is partially right (full path names if outside the used $PATH variable), partially superfluous (the cron daemon already executes cron jobs with '/bin/sh' or what the SHELL variable says it should use) and partially bothersome as you'd have to wait until a quarter past the hour to see its effect. Your cron job uses full path names correctly but would have cron execute the job each minute. Usually you don't want that ;-p


Quote:
Originally Posted by Mainer44 View Post
Regarding using the common crontab entry method, that was the only way I knew of to create and activate a crontab until yesterday when I happened upon the aforementioned book
It's not a bad method but a crontab may already hold lines so it's better to "export" it, add to it and then reload the crontab. Terse example:
Code:
#!/bin/sh --
# Set debug mode when testing and set default behaviour:
set -vx; LANG=C; LC_ALL=C; export LANG LC_ALL
TMPFILE=`mktemp -p /tmp crontab.XXXXXXXXXX` && {
 crontab -l > "${TMPFILE}"
 echo '*/15 * * * * /home/username/bin/backup.sh' >> "${TMPFILE}"
 crontab "${TMPFILE}"; rm -f "${TMPFILE}"
}; exit 0

Quote:
Originally Posted by Mainer44 View Post
Sadly despite lots of searching I was unable to locate any logs that were helpful. I tried to find the directories and files that were suggested and couldn't find them or figure out how to read them.
Well now you know.


Quote:
Originally Posted by Mainer44 View Post
I did not activate the MAILTO option.
That's OK. Only if you want to change behaviour you would modify or unset it: the default is to not mess with it.


Quote:
Originally Posted by Mainer44 View Post
Linux is brand new to me and I seem to be facing a steep learning curve.
Just do stuff. Best way to learn. If it breaks ask, if it doesn't consider yourself lucky ;-p
BTW Telengard posted a nice "Learning the Linux Command Line" link collection here: http://www.linuxquestions.org/questi...nd-line-32893/


Quote:
Originally Posted by Mainer44 View Post
I am brand new to scripting also.
Ah, OK. Here's some Bash scripting guides, just don't read or try to grok them all at once:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://www.gnu.org/software/bash/man...ode/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls


Quote:
Originally Posted by Mainer44 View Post
when one uses the command 'crontab -e' is that saved in the users home directory or in the root directory?
The system stores cron tabs in /var/spool/cron or equivalent.


Quote:
Originally Posted by Mainer44 View Post
In either case, isn't '/home/username/bin/backup.sh' the absolute path that can be accessed from anywhere in the filesystem?
As long as $username has access to /home/$username/bin/ and its contents, yes.
 
Old 02-24-2013, 03:15 PM   #22
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,555

Rep: Reputation: 463Reputation: 463Reputation: 463Reputation: 463Reputation: 463
Quote:
Originally Posted by shivaa View Post
@lleb:
It's just a matter of choice, quoting doesn't make any difference.
ok good to know. i thought i was making a mistake or something.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trouble With FOR Loop In Simple Bash Script sudleyplace Linux - Newbie 7 03-12-2008 04:55 AM
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
Having trouble with a simple script Arcturuss Linux - Newbie 1 12-03-2007 01:10 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM


All times are GMT -5. The time now is 08:32 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration