[SOLVED] Script works in the shell but not with cron |
| User |
Message Verfasst:
05.09.2011 13:05 |
cmatte unregistered
 |
|
I'm new to newnigma2 on dm8000 and I am having a problem with Cron. I installed it normally and it's cron - 3.0pl1-r15. I've written my cronjob in /cron/tabs/root and it is simply:
| code: |
1:
2:
3:
4:
5:
6:
7:
|
# Crontab di esempio
# Spegne il decoder ogni giorno alle ore 04:00
# 0 4 * * * /etc/cron/scripts/standby.sh
*/1 * * * * /media/usb/cron_jobs #date,OSCam,Samba
|
|
I see cron is auto-running:
| code: |
1:
2:
3:
4:
5:
|
root@dm8000:~# ps | grep cron
5788 root 2044 S /usr/sbin/cron
5932 root 2596 S grep cron
|
|
I also see in cron log at /cron/log that it is launching the command every other minute as expected:
| code: |
1:
2:
3:
|
root (09/05-12:56:00-6497) CMD (/media/usb/cron_jobs #date,OSCam,Samba)
root (09/05-12:57:00-6521) CMD (/media/usb/cron_jobs #date,OSCam,Samba) |
|
So it all seems right.
That script in usb is quite long to be written here but basically it just adjusts the date from the net with a script and restarts oscam and samba if they're not running for any reason. And I can see it IS working because if I run it from terminal writing /media/usb/cron_jobs it just does its duties i.e. restarting samba that usually crashes without reason.
But strangely it does not do its duties with cron. I ask, what could be the reason? I tried crontab -e, relaunching cron, etc, but it does not do what it is expected to do. The only fact I don't understand is this error running "cron" manually:
| code: |
1:
|
cron: can't lock /var/run/cron.pid, otherpid may be 5900: Resource temporarily unavailable |
|
but I don't think that's a real problem. That file contains the right pid, has the right permissions, start/stop/restart init.d script works as expected.
Hope someone got and idea.
This post has been edited 3 time(s), it was last edited by cmatte: 06.09.2011 09:42.
| | |
|
|
| User |
Message Verfasst:
05.09.2011 14:40 |
cmatte unregistered
 |
|
| quote: |
Originally posted by Fred Bogus Trumper
cron works well on NN2 3.2.2 on all my boxes |
I did not confess I do a quite bad thing: add unstable repos to opkg and install today's updates. Very probably I'm just having problems due to this, but I didn't try cron before and can't be sure atm.
| quote: |
Originally posted by Fred Bogus Trumper
are the scripts executable?
|
Yes all 755.
| quote: |
Originally posted by Fred Bogus Trumper
did u use an Linux-Editor (vi, nano, PS-Pad ...)? or using crontab -e on the commandline? |
I am on Windows, but I am using Notepad++ that makes me able to edit/write scripts with unix-like endline characters. In fact the script just runs well from the shell. I tried crontab -e and the file is there too.
| quote: |
Originally posted by Fred Bogus Trumper
do the path /media/usb exist? I mean is a divice mounted on /media/usb? in Newnigma2 u will find all USB-Devices in /autofs/ |
Yes, I managed to edit /etc/fstab because my usb stick was mounted to /hdd and my hdd was not mounted at all (only on autofs as you say). So I have just changed right sdX to /media/usb and sdY to /media/hdd. Paths are ok.
| quote: |
Originally posted by Fred Bogus Trumper
try a reboot or reinstall cron |
Just tried, also tried removing unstable branch, update opkg, remove cron, reinstall cron even if I see it's the same exact version. In fact it didn't work.
If you have some other ideas I'll try them out, or see if tomorrow this is resolved in unstable branch, then remove it definitively since it has very disadvantages and I still can retrieve particular packets I need from there manually.
Thanks for your help.
This post has been edited 3 time(s), it was last edited by cmatte: 05.09.2011 14:41.
| | |
|
|
| User |
Message Verfasst:
05.09.2011 15:20 |
sparksofinsanity
DAU
   

Registration Date: 21.03.2010
Posts: 9,638
User Offline
1. Dreambox: 8000sscc 2. Dreambox: 7020HD
 |
|
| quote: |
| Yes, I managed to edit /etc/fstab because my usb stick was mounted to /hdd and my hdd was not mounted at all (only on autofs as you say). So I have just changed right sdX to /media/usb and sdY to /media/hdd. Paths are ok. |
your HardDisk is connected to the wrong SATA Port, one of the Ports is a SATA/USB-Bridge
| quote: |
| or see if tomorrow this is resolved in unstable branch |
cron is working absolutely correct, there is nothing to fix
__________________ Panasonic TX-P42GT50
| | |
|
|
| User |
Message Verfasst:
05.09.2011 17:54 |
cmatte unregistered
 |
|
| quote: |
Originally posted by sparksofinsanity
your HardDisk is connected to the wrong SATA Port, one of the Ports is a SATA/USB-Bridge |
I didn't specify the hd is an external USB one. Should I use a specific usb port for it?
I see the system recognizes it is an hd and the usb stick as a stick (by the menu) and I see it was already mounting them to autofs folder. No particular problems. I just liked 1. not to have the stick mounted on /media/hdd and 2. hdd there and stick to /media/usb .... all just because I was using another image (SifTeam) and it just mounted them this way, so all my own scripts was using these paths and I didn't want to bore editing them all.
And editing fstab just solved it all in two lines
| quote: |
Originally posted by sparksofinsanity
cron is working absolutely correct, there is nothing to fix |
Here it is not. Have you read my first post completely? Cron starts, continues to work, reads the root file with the script, crontab reports it, the log indicates it runs the script, but in fact that file is NOT run. If I manually run the file it DOES run and it DOES do what it is intended to do. I can't explain this to myself, that's why I am asking your help
----------edit-------------
Just found out the script is run because other things it does are done correctly. It's only the samba "part" of it that isn't run correctly and I don't understand why. Strange fact is that it worked in the old image, and it works if I run the script from the shell
This is the "possessed" part
:
| code: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
|
#check Samba daemon
if [ `ps | grep smbd | grep -v grep | wc -l` = 0 ]
then
killall nmbd
sh /etc/network/if-up.d/01samba-start
fi
|
|
For what reason on earth would this run perfectly in a shell and not "under" a cron running schedule?
Hope someone can explain, I'm really out of ideas....
---------edit 1---------
Just got some information about cron and how it works. I see it creates its own simply environment that could be different from the shell one. I don't know how this would deny smbd and nmbd starting normally but it simply did this.
That's what I've done:
from the shell:
env > /tmp/baseenvironment.env
Then simply add all in the top of the cronjob file.
smbd and nmbd daemons are now fully restarted and working.
There's always something to learn you can't even imagine
-------edit 2------
Btw, this is what is missing or different:
| code: |
1:
2:
3:
4:
5:
6:
7:
|
USER=root
PS1=\u@\h:\w\$
TERM=xterm
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:
EDITOR=/bin/vi
|
|
This post has been edited 4 time(s), it was last edited by cmatte: 05.09.2011 19:03.
| | |
|
|
|