The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Operating Systems
> Linux Help
|
Schedluled cron job stpped working
Discuss Schedluled cron job stpped working in the Linux Help forum on Dev Shed. Schedluled cron job stpped working Linux Help forum discussing topics including usage, troubleshooting, modules, and distributions. Linux is an open source OS, based on UNIX.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 22nd, 2011, 02:32 AM
|
|
Contributing User
|
|
Join Date: May 2005
Posts: 325
Time spent in forums: 3 Days 5 h 5 m 8 sec
Reputation Power: 9
|
|
|
Scheduled cron job stopped working
Hi
I run a Fedora 9 server at home, to host an "old school" MOO.
To back up the database, I scheduled a cron job - and got some help with the script.
Code:
#!/bin/bash
FILENAME="muddle_`date +%Y-%m-%d_%H:%M`.db.new"
cp /home/xxxxx/mooxxx/bin/muddle.db.new "/home/xxxxx/mooxxx/bin/$FILENAME"
mv "/home/xxxxx/mooxxx/bin/$FILENAME" /root/Dropbox/
That worked fine over about a year, till sometime in May, when it just stopped working.
The error is:
Code:
mv: cannot stat `/root/Dropbox/muddle_2011-08-22_17:12.db.new': Permission denied
I don't fiddle with stuff on the server much, because I don't really have a clue - leave well enough alone.
But now I'm without backups. (I'd prefer to get this working, as it seemed pretty simple, and worked well for so long).
Anyy suggestions?
Woger
Last edited by woger : August 22nd, 2011 at 05:21 AM.
|

August 22nd, 2011, 03:57 AM
|
|
|
|
The major hints are the 'cannot stat' - which generally means 'cannot find' and the 'permission denied' which generally means what it says.
Could be a few things, which would require you to check the permissions of files and directories. But, one additional thing that springs to mind is that whilst you are moving your backups into the /root/Dropbox directory you do not mention doing any housekeeping. You may also wish to check how full the /root file system is.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
|

August 22nd, 2011, 04:18 AM
|
|
Contributing User
|
|
Join Date: May 2005
Posts: 325
Time spent in forums: 3 Days 5 h 5 m 8 sec
Reputation Power: 9
|
|
Thank you...hopefully I can answer your suggestions intelligently.
I ran a ls -l to get permissions. Here's where they are at:
Code:
drwx------ 4 root root 16384 2011-08-22 19:01 Dropbox
-rwxrwxrwx 1 root root 206 2011-08-22 17:20 back.sh
With regard to housekeeping - I'm not sure what I need to do? All going well, once the file is moved to the dropbox directory, it automatically gets uploaded. I do remove files from the local dropbox intermittently. Dropbox has never exceeded about 58% capacity - each file is now approaching 6mb
Hopefully that gives the Linux epxerts some clues to help me out - way over my head here!!!!!
woger
Last edited by woger : August 22nd, 2011 at 04:53 AM.
|

August 25th, 2011, 08:56 AM
|
|
|
|
This script is part of the root crontab?
What happens if you run it by hand using: bash -x back.sh (assuming back.sh is the script in question)?
|

August 25th, 2011, 08:22 PM
|
 |
Contributing User
|
|
|
|
|
script explained, not fixed.
Code:
0 #!/bin/bash
1 FILENAME="muddle_`date +%Y-%m-%d_%H:%M`.db.new"
2 cp /home/xxxxx/mooxxx/bin/muddle.db.new /root/Dropbox/"$FILENAME"
Line 0 tells the command line interpreter to invoke /bin/bash to read the script.
Line 1 sets the shell variable FILENAME to the string on the right side of the assignment token (=).
However, the string is double quoted and therefore subject to some further expansions. The output (stdout) of the date command between back-quotes is substituted for the `back tick command`. Back-ticks are depricated. Use $( command ) instead. Why bother to quote the phrase at all? The stuff between the quotes is one word even if it contains space characters.
Line 2 copies the file directly to /root/Dropbox with the new name. I cannot think of a reason to copy the file and then move it, so I changed your script. There's a good chance /root/Dropbox and /home/me are on different file systems and so the commands in your script would effectively copy the file twice. At least I'm pretty sure that's how it works. But anyway, lastly, $FILENAME substitutes the value of the variable. And since in double quotes retains the single word business.
'Single quoted strings in the shell script' are one word, nothing gets substituted.
|

August 27th, 2011, 01:44 AM
|
|
Contributing User
|
|
Join Date: May 2005
Posts: 325
Time spent in forums: 3 Days 5 h 5 m 8 sec
Reputation Power: 9
|
|
Still not a lot of luck... Although perhaps some progress.
I modified the script first.
Code:
#!/bin/bash
FILENAME="muddle_date +%Y-%m-%d_%H:%M.db.new"
#cp /home/basil/moo3/bin/muddle.db.new "/home/basil/moo3/bin/$FILENAME"
#mv "/home/basil/moo3/bin/$FILENAME" /root/Dropbox/
cp /home/basil/moo3/bin/muddle.db.new /root/Dropbox/"$FILENAME"
The error this time was: cp: accessing `/root/Dropbox/xxxxe_date +%Y-%m-%d_%H:%M.db.new': Permission denied
I then tried to run it from the command line.
Code:
[root@bin]# bash -x back.sh
+ FILENAME='xxxxx_date +%Y-%m-%d_%H:%M.db.new'
+ cp /home/xxxx/xxxx/bin/xxxxx.db.new '/root/Dropbox/xxxxx_date +%Y-%m-%d_%H:%M.db.new'
That has copied the file, and dropbox has done it's thing. But the file name appears as-
Code:
xxxx_date +%Y-%m-%d_%H:%M.db.new
rather than appending the date to the the datbase name.
Hope that makes sense.
|

August 27th, 2011, 04:13 AM
|
|
|
|
You've altered the date command, and removed the 'command ticks' to get the shell to recognise it as a command. You should go back to using ` .. ` or better, as suggested by b49P23TIvg use $( .. )
FILENAME="muddle_$(date +%Y-%m-%d_%H:%M).db.new"
|

August 27th, 2011, 05:18 AM
|
|
Contributing User
|
|
Join Date: May 2005
Posts: 325
Time spent in forums: 3 Days 5 h 5 m 8 sec
Reputation Power: 9
|
|
Quote: | Originally Posted by SimonJM You've altered the date command, and removed the 'command ticks' to get the shell to recognise it as a command. You should go back to using ` .. ` or better, as suggested by b49P23TIvg use $( .. )
FILENAME="muddle_$(date +%Y-%m-%d_%H:%M).db.new" |
Gotcha. So that runs fine from command line. But how do I get cron to run it automatically. It still says permission denied.
|

August 27th, 2011, 10:35 AM
|
|
|
|
OK, so we have a script that functions correctly when called from the command line? That's a good start!
Now, can you confirm that the user you use to run the script at the command line is the samr as the user running it via cron? The raeson I ask is that your Dropbox directory is only available to the root user and I'd suspect that your moo runs under another user, which makes me think your backup also runs as that user (basil) which will cause permission issues.
If the script is running from cron as as user other than root then wel will need to make some changes - I'd suggest either changing Dropbox so that it is owned by the relevant user or look into setting up a group and giving that rwx access to Dropbox and adding the user that runs the moo and/or the script into the group.
|

August 27th, 2011, 05:29 PM
|
|
Contributing User
|
|
Join Date: May 2005
Posts: 325
Time spent in forums: 3 Days 5 h 5 m 8 sec
Reputation Power: 9
|
|
It was setup over 12 months ago, but....
The script runs from a directory under basil.
(I was trying to avoid security issues by running as root).
But permissions wise, I set it up as:
Code:
-rwxrwxrwx 1 root root 274 2011-08-27 20:11 back.sh
And , yes, for some reason, dropbox is installed under root. But I think that's because that's the only way I could get webmin to work. (I'm not really good at CLI - so i look for GUIs).
Permissions wise though, this did work for over 12 months. Basil does belong to an admin group.
Cheers
|

August 27th, 2011, 08:02 PM
|
 |
Contributing User
|
|
|
|
|
Out of date, but still useful?
This post is a response to
Today, 02:44 AM
woger Contributing User
sorry, screwy internet? screwy me? screwy Irene? (the local hurricane, for those of you reading this message in the far future when you're dealing with different weather issues, or from other countries where you have super typhoons.)
FILENAME="muddle_$( date +%Y-%m-%d_%H:%M.db.new )"
I thought my explanation was rather good. Perhaps you'd read the whole thing? And, so as to be not completely snotty, you can experiment on the command line with commands like
echo FILENAME="muddle_$( date +%Y-%m-%d_%H:%M.db.new )"
echo '$( date )' "$( date )" $( date ) computation $(( 38+2342 ))
Last edited by b49P23TIvg : August 27th, 2011 at 08:56 PM.
Reason: this post is out of date
|

August 27th, 2011, 08:21 PM
|
|
Contributing User
|
|
Join Date: May 2005
Posts: 325
Time spent in forums: 3 Days 5 h 5 m 8 sec
Reputation Power: 9
|
|
Quote: | Originally Posted by b49P23TIvg FILENAME="muddle_$( date +%Y-%m-%d_%H:%M.db.new )"
I thought my explanation was rather good. Perhaps you'd read the whole thing? And, so as to be not completely snotty, you can experiment on the command line with commands like
echo FILENAME="muddle_$( date +%Y-%m-%d_%H:%M.db.new )"
echo '$( date )' "$( date )" $( date ) computation $(( 38+2342 )) |
Thanks. From the CLI - as you suggest - that's fine.
Learnt a few things there.
Permission error still from cron.
|

August 27th, 2011, 10:15 PM
|
|
|
Strange, and sorry to get you to do CLI stuff (which I prefer!) instead of GUI stuff
Rats ... let's try that command again ...
Code:
FILENAME=muddle_$(date "+%Y-%m-%d_%H:%M").db.new
Is, I think, what you should be using. Hopefully, from the command line (sorry!) you do what b49P23TIvg suggests, as a debug aid, and replicate the command but using echo:
Code:
echo muddle_$(date "+%Y-%m-%d_%H:%M").db.new
you should be able to confirm it will be doing what you want.
Likewise, running the script from the command line using bash -x which will show how each line is evaluated will help confirm it is working when within the script.
Once we have all those 'ducks lined up' we get to the nub of the problem, which is why it causes an error when run as cron.
Can you show us (sanitised if you wish) output from the commands:
Code:
crontab -u root -l
crontab -u basil -l
|

August 27th, 2011, 10:28 PM
|
|
Contributing User
|
|
Join Date: May 2005
Posts: 325
Time spent in forums: 3 Days 5 h 5 m 8 sec
Reputation Power: 9
|
|
Code:
Can you show us (sanitised if you wish) output from the commands:
[CODE]crontab -u root -l
crontab -u basil -l
[/QUOTE]
Results from CLI -
[root@sbc ~]# crontab -u root -l
20 3 * * * /etc/webmin/cron/tempdelete.pl
[root@sbc ~]# crontab -u basil -l
@daily /home/xxxx/moo3/bin/back.sh
[root@sbc ~]#
|

September 8th, 2011, 01:21 AM
|
|
Contributing User
|
|
Join Date: May 2005
Posts: 325
Time spent in forums: 3 Days 5 h 5 m 8 sec
Reputation Power: 9
|
|
|
The problems seem to be:
My MOO doesn't run as root - for security reasons.
And CRON needs to (or so I thought). Any suggestions to be able to get the cron job working again?
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|