You are not logged in.

Dear visitor, welcome to Newnigma2. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

cmatte

Unregistered

1

Monday, September 5th 2011, 1:05pm

[SOLVED] Script works in the shell but not with cron

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:

Source code

1
2
3
4
5
6
# 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:

Source code

1
2
3
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:

Source code

1
2
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:

Source 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 times, last edit by "cmatte" (Sep 6th 2011, 9:42am)


Posts: 2,960

1. Dreambox: 7020HD

2. Dreambox: 800SE-s

Kabelanbieter/Cableprovider: DM800SE-C/T, DM7020si, DM500S

  • Send private message

2

Monday, September 5th 2011, 1:15pm

RE: Cron not working?

cron works well on NN2 3.2.2 on all my boxes

are the scripts executable?
did u use an Linux-Editor (vi, nano, PS-Pad ...)? or using crontab -e on the commandline?

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/

try a reboot or reinstall cron
Gruß Fred

This post has been edited 1 times, last edit by "Fred Bogus Trumper" (Sep 5th 2011, 1:15pm)


cmatte

Unregistered

3

Monday, September 5th 2011, 2:40pm

RE: Cron not working?

Quoted

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.

Quoted

Originally posted by Fred Bogus Trumper
are the scripts executable?

Yes all 755.

Quoted

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.

Quoted

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.

Quoted

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 times, last edit by "cmatte" (Sep 5th 2011, 2:41pm)


sparksofinsanity

Unregistered

4

Monday, September 5th 2011, 3:20pm

Quoted

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

Quoted

or see if tomorrow this is resolved in unstable branch


cron is working absolutely correct, there is nothing to fix

cmatte

Unregistered

5

Monday, September 5th 2011, 5:54pm

Quoted

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 :)

Quoted

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 :aufgeben:

----------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 8o :

Source code

1
2
3
4
5
6
7
#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 8)

-------edit 2------
Btw, this is what is missing or different:

Source code

1
2
3
4
5
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 times, last edit by "cmatte" (Sep 5th 2011, 7:03pm)


Rate this thread