This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Beaglebone Having problems with i2cget withing a cron started script or application

I am trying to shutdown linux  ( Linux beaglebone 3.8.13 #1 SMP Wed Jun 5 11:21:00 CEST 2013 armv7l GNU/Linux  )when the AC power cord is removed from the beaglebone, I have a battery backup attached.

I have tried multiple shell files and python scripts and finally an application. If I run any from the cli things work just fine. If I run form cron with @reboot I can see from the logs that the i2cget return nothing.

I have tried scripts starting other scripts, I have tried starting scripts with nohup I have tried a lot of stuff.

What am I missing here, all I need to do is read register 10 (0xA) of the PMIC (i2cget -y -f 0 0x24 0xA) and if bit 4 is zero call shutdown.

If anyone can help I would be grateful

thanks.

the application main follows:

main(int argc, char *argv[])
{
  FILE *fp;
  char path[64];
  int  res;
  if(log_init("pmon.log") != RC_OK)
  {
   printf("cannot open file for logging\n");
  }
  slog(1,"Log Starter");
  while(1)
  {
   fp = popen("i2cget -f -y 0 0x24 0xa","r");
   if(fp == NULL)
    {
     slog(1,"failed to open pipe \n");
     exit(-1);
    }
   fgets(path,64,fp);
   slog(1, "i2cget = %s",path);
   res = (int)strtol(path,NULL,0);
   pclose(fp);
   if((((unsigned char)res) & 0x8) == 0)
   {
    slog(1,"Noted AC power gone.");
    fp=popen("shutdown","r");
    if(fp == NULL)
     {
      slog(1,"failed to open pipe \n");
      exit(-1);
     }
     pclose(fp);
     exit(0);
   }
   sleep(5);
  }
}