[RESOLVED] Help please: CRON works on one Omega2+ but not the other.
-
I have two Omega2+ one of which is mounted on the Power Dock and the other is mounted on the Expansion Dock
The cron on the Omega2+ on the Expansion works. I've written a small shell script to make the Omega LED go into heartbeat mode and then return to default-on. I scheduled it to run every minute.
When I place the same program on the Omega2+ on the Power Dock and create the exact same crontab entry pointing to the same shell script (same directory structure as the other Omega2+), the cron does not run the script. Very strange.
The steps were:- Create the shell script
- set it to executable
- create the cron entry via crontab -e
- restart the cron /etc/init.d/cron restart
If I manually run the script, it works just fine.
Any idea what could be the issue or the best remedy to get this sucker working?
-
Update 1
Reloaded the latest version omega2p-v0.1.9-b155.bin
No change.
Removed the OLED board just in case.
No change. -
Update 2
It would appear that the cron is trying to do something.
The cron entry looks like this
*/1 * * * * /root/my.sh > /tmp/output1.txt 2>$1
It is creating the output1.txt file but nothing is being written to it as is the case on the other Omega2+ which means that the script /root/my.sh is not being run. Why?
This is where I'm at a loss. I've no idea how the scheduler invokes the script. I'm now of the view that something is corrupted in the OS. I've performed a factory reset and gone through the process of initialising the Omega as if it was brand new out of the box but that has not solved the issue unless I missed something in the installation sequence.
-
This post is deleted!
-
Update 3
The script I am using in the cron entry for the Omega2+ on the Power Dock:
# !/bin/ash -e # Filename: my1.sh # Description: Controls the Omega2+ LED # Rapidly pulses the LED echo timer > /sys/class/leds/omega2p\:amber\:system/trigger echo 75 > /sys/class/leds/omega2p\:amber\:system/delay_on echo 75 > /sys/class/leds/omega2p\:amber\:system/delay_off sleep 4 echo default-on > /sys/class/leds/omega2p\:amber\:system/trigger cat /sys/class/leds/omega2p\:amber\:system/trigger date
Turns the LED on to rapid pulse for 4 seconds, then resets the LED to ON then displays the trigger status and date, then exits.
The cron entry to invoke the script every minute.
root@Omega-6049:~# crontab -l # MM HH DD MM DOW #*/1 * * * * /root/squote.sh >> /tmp/output.txt 2>$1 */1 * * * * /root/my1.sh > /tmp/output1.txt 2>$1 # last line must be a comment
[Edit] as @György-Farkas posted below the error is in the crontab entry. I mistakenly entered a $ instead of an &. The
2>&1
is an indicator to the shell script that you want to include the error messages into the output of your command.root@Omega-6049:~# crontab -l # MM HH DD MM DOW #*/1 * * * * /root/squote.sh >> /tmp/output.txt 2>&1 */1 * * * * /root/my1.sh > /tmp/output1.txt 2>&1 # last line must be a comment
snapshot of ps to show the cron is operational
root@Omega-6049:~# ps | grep cron 9098 root 1188 S /usr/sbin/crond -f -c /etc/crontabs -l 8 12240 root 1184 S grep cron
At the moment (or a second after) the cron should invoke the script there should be an entry in the process list to show that it is running.
root@Omega-6049:~# ps | grep sh 1845 nobody 1292 S /usr/sbin/shellinaboxd -t --service=/:LOGIN --css /usr/lib/shellinabox/style.css 1857 nobody 1292 S /usr/sbin/shellinaboxd -t --service=/:LOGIN --css /usr/lib/shellinabox/style.css 8505 root 1192 S -ash 11322 root 896 S /sbin/askfirst /usr/libexec/login.sh 12342 root 0 Z [sh] 12345 root 1184 S grep sh
As you can see there is no line matching that would indicate that my1.sh is running except that process number 12342 is suspect.
On my other Omega2+ (which is working as expected on the Expansion Dock) the script I am running on the minute is as follows:
#!/bin/ash -e # Filename: my.sh # Description: Controls the Omega2+ LED echo timer > /sys/class/leds/omega2p\:amber\:system/trigger echo 75 > /sys/class/leds/omega2p\:amber\:system/delay_on echo 75 > /sys/class/leds/omega2p\:amber\:system/delay_off sleep 4 echo default-on > /sys/class/leds/omega2p\:amber\:system/trigger cat /sys/class/leds/omega2p\:amber\:system/trigger date
The cron entry (the second one).
root@Omega-B779:~# crontab -l # MM HH DD MM DOW */1 * * * * /root/rgb-control.sh > /tmp/output.txt 2>&1 */1 * * * * /root/my.sh > /tmp/output1.txt 2>&1 # last line must be a comment root@Omega-B779:~#
snapshot of the ps just after the minute mark
root@Omega-B779:~# ps | grep sh 453 root 896 S /sbin/askfirst /usr/libexec/login.sh 2430 nobody 1292 S /usr/sbin/shellinaboxd -t --service=/:LOGIN --css /usr/lib/shellinabox/style.css 2439 nobody 1292 S /usr/sbin/shellinaboxd -t --service=/:LOGIN --css /usr/lib/shellinabox/style.css 13521 root 1184 S /bin/sh -c /root/rgb-control.sh > /tmp/output.txt 2>&1 13522 root 1184 S /bin/sh -c /root/my.sh > /tmp/output1.txt 2>&1 13523 root 1184 S {my.sh} /bin/ash -e /root/my.sh 13524 root 1184 S {rgb-control.sh} /bin/ash /root/rgb-control.sh 13527 root 1184 S {rgb-led.sh} /bin/sh -e /root/rgb-led.sh 13774 root 1184 S grep sh 18469 root 1184 S -ash
Process number 13523 is in progress so on this Omega2+ everything is working nicely.
The contents of the output1.txt file to show that the process ran as expected.
root@Omega-B779:/tmp# cat output1.txt none timer [default-on] netdev transient mmc0 gpio heartbeat morse oneshot Sun Feb 12 12:39:04 AWST 2017 root@Omega-B779:/tmp#
If I swap the suspect Omega2+ from the Power Dock to this one (Expansion Dock), the issue with the cron still exists so it is not Dock related.
Any ideas?
-
There are two typos in the first cron entry, there is $ instead of &
/root/squote.sh >> /tmp/output.txt 2>$1
/root/my1.sh > /tmp/output1.txt 2>$1/root/squote.sh >> /tmp/output.txt 2>&1
/root/my1.sh > /tmp/output1.txt 2>&1logread | tail
can show you that cron runs and allows to run your script.Good luck!
-
@György-Farkas well spotted.
-