1

I made a script that sends my local sensors temperature to a server in the internet and then I can see a graph of it. Everything works fine when I execute it manully. I have the latest ubuntu version. When it comes to run periodically every minute with crontab then nothing works. It doesnt send anything. I tried to run it as SUDO and as user, I tried to add it in the crontab file to run it from several locations like /bin/myscript.sh , /user/Desktop and many others...Nothing seems to work. Any Idea how to solve it? Thank you!

   echo Init ... 
   TEMP=`/usr/bin/snmpwalk  -v 1 -c public 192.168.1.2 iso.3.6.1.4.1.38783.3.9.0 |  cut -d" " -f4` 
   echo $TEMP


   REALTEMP=`echo  "scale=1; $TEMP/10"  | bc -l`
   echo $REALTEMP 

   echo 
   wget "http://api.thingspeak.com/update?key=MYKEY=$REALTEMP"
Jorge Castro
  • 71,754
Vagelism
  • 189

4 Answers4

3

Assuming your crontab line just contains the script name, you need specify what should execute the script, either in crontab (assuming it should run with bash shell)

/5 * * * * /bin/bash /path/to/myscript.sh

or by adding a ``shebang'' line at the beginning of the script

#!/bin/bash

It is not obvious that the script depends on any environment variables, but it is worth noting a cron job runs with only HOME, LOGNAME, PATH, and SHELL set.

The script file also needs to be executable (chmod +x myscript.sh).

chronitis
  • 12,367
2

I had a similar issue getting cron to recognize a command on a server of mine. The tip that solved my issue came from the troubleshooting section of the Ubuntu Cron Howto:

When adding a new entry to a blank crontab, forgetting to add a newline at the end is a common source for the job not running. If the last line in the crontab does not end with a newline, no errors will be reported at edit or runtime, but that line will never run. See man crontab for more information. This has already been suggested as a bug.

glibdud
  • 747
1

I don't have any clue about your script issue, but if your need is to have some realtime charts about the sensors' temperature available through a web server you can give a try to psensor-server.

It is available in the standard ubuntu repositories, so you can install it easily with 'sudo apt-get install psensor-server', run 'psensor-server', and finally open the URL 'http://hostname:3131'. You will get this kind of charts:

enter image description here

Alternatively, you can retrieve programmaticaly as a JSON output the temperatures using 'http://hostname:3131/api/1.0/sensors'.

green
  • 14,306
JeanFI
  • 1,430
  • 1
  • 12
  • 9
0

Thank you all for your help. I manage to do it runing as a service with the help that I found in this site You can do what he said. Or, you can do this, which will run ANY sript for you.

  1. First, create a script, and edit it to your needs. Lets say, you call it, autorun.sh
  2. Copy that script into /etc/init.d
  3. Run the following commands:

    sudo update-rc.d autorun.sh defaults

    sudo chmod +x /etc/init.d/autorun.sh

Again thank you all for your advices. I really didnt have time to check them all. I will do it soon!

devav2
  • 36,312
Vagelism
  • 189