Linvincible wrote: 
> Hi, yes I did change the first line to #!/bin/sh
> I thought the error message came from rights on the script itself but
> they didn't : it was the rights on files accessed inside that mattered.
> Weired, usually it says error at line x in these cases...
> Anyway I changed the rights to the files accessed and it works now.
> 
> I just can't use shutdown command, any reason why?
> 
> here's the script as it is now, may need a bit of refinement I'll submit
> it to the msldigital.com guys:
> 
> #! /bin/sh
> # 22 is the GPIO pin receiving the shut-down signal
> 
> sudo chown tc /sys/class/gpio/export
> sudo echo "22" > /sys/class/gpio/export
> sudo chown tc /sys/class/gpio/gpio22/direction
> sudo chown tc /sys/class/gpio/gpio22/value
> sudo echo "in" > /sys/class/gpio/gpio22/direction
> while true; do
> 
> sleep 1
> power=$(cat /sys/class/gpio/gpio22/value)
> if [ $power != 0 ]; then
> sudo echo "out" > /sys/class/gpio/gpio22/direction
> sudo echo "1" > /sys/class/gpio/gpio22/value
> sudo poweroff
> fi
> 
> done

hi Linvincible,

Can I first stay I am not a Linux expert, so I hope I am not misleading
you.

I am not 100% sure using sudo and changing ownership is the best
solution. Often assessing hardware is meant to be a root function. Here
is an example of "working" code I have used when testing a hardware
Pause/Play button on piCorePlayer. I can't remember if I initialised the
script by #sudo ./button &  or #sudo su then #./button &.


Code:
--------------------
    
  #!/bin/sh
  
  player=started
  
  echo "17" > /sys/class/gpio/export
  echo "in" > /sys/class/gpio/gpio17/direction
  
  while true
  do
  PRESSED=$(cat /sys/class/gpio/gpio17/value)
  echo $PRESSED
  sleep 1
  if [ $PRESSED = 0 ]; then
                if [ $player = stopped ]; then
                        echo "Start player"
                        echo "play" | telnet 192.168.1.101:9090
                        player=started
                        sleep 3
                else
                        echo "Stop player"
                        echo "stop" | telnet 192.168.1.101:9090
                        player=stopped
                        sleep 3
                fi
  fi
  done
  
  echo "17" > /sys/class/gpio/unexport
  
  exit
  
  
--------------------


Some GPIO extensions put a wrapper around the basic GPIO operations and
may allow non-root access.

I prefer to use this piCore code to shutdown piCorePlayer.


Code:
--------------------
    exitcheck.sh
--------------------


regards
Greg


------------------------------------------------------------------------
Greg Erskine's Profile: http://forums.slimdevices.com/member.php?userid=7403
View this thread: http://forums.slimdevices.com/showthread.php?t=97803

_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to