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

    • [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:

      Quellcode

      1. # Crontab di esempio
      2. # Spegne il decoder ogni giorno alle ore 04:00
      3. # 0 4 * * * /etc/cron/scripts/standby.sh
      4. */1 * * * * /media/usb/cron_jobs #date,OSCam,Samba
      I see cron is auto-running:

      Quellcode

      1. root@dm8000:~# ps | grep cron
      2. 5788 root 2044 S /usr/sbin/cron
      3. 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:

      Quellcode

      1. root (09/05-12:56:00-6497) CMD (/media/usb/cron_jobs #date,OSCam,Samba)
      2. 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:

      Quellcode

      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.

      Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von cmatte ()

    • 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

      Die Dreambox ist tot, es lebe die Dreambox

      ¯\_(ツ)_/¯

      Quellcode

      1. root@dm920:~$ mount | grep "/ "
      2. /dev/mmcblk1p1 on / type ext4 (rw,relatime,data=ordered)
      3. root@dm920:~$

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Fred Bogus Trumper ()

    • RE: Cron not working?

      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.

      Originally posted by Fred Bogus Trumper
      are the scripts executable?

      Yes all 755.
      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.

      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.

      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.

      Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von cmatte ()

    • 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

      or see if tomorrow this is resolved in unstable branch


      cron is working absolutely correct, there is nothing to fix
    • 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 :)
      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 :

      Quellcode

      1. #check Samba daemon
      2. if [ `ps | grep smbd | grep -v grep | wc -l` = 0 ]
      3. then
      4. killall nmbd
      5. sh /etc/network/if-up.d/01samba-start
      6. 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:

      Quellcode

      1. USER=root
      2. PS1=\u@\h:\w\$
      3. TERM=xterm
      4. PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:
      5. EDITOR=/bin/vi

      Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von cmatte ()