# Shell script from /sdcard ?



## acejavelin

OK, so I made a simple little shell script to store logcat output called logscript to an sdcard directory and put it in /sdcard, then did 'chmod 755 /sdcard/logscript" and when I try execute it I am getting a permissions error... what am I doing wrong? Each entry in the shell script executes just fine by itself, but as soon as I execute the script itself, it just immediately says "Permissions error"


----------



## dwitherell

acejavelin said:


> OK, so I made a simple little shell script to store logcat output called logscript to an sdcard directory and put it in /sdcard, then did 'chmod 755 /sdcard/logscript" and when I try execute it I am getting a permissions error... what am I doing wrong? Each entry in the shell script executes just fine by itself, but as soon as I execute the script itself, it just immediately says "Permissions error"


Hmm... maybe (with r/w permissions set on /system of course) try to move the script to /system/bin/ - you'll likely have to give it 755 permissions again there. Then you should be able to run it from terminal - just enter the file name. This has worked for me in the past anyway. Also - I'm not sure but you may need to throw an su in there before running it - sort of depends on the commands used in the script.


----------



## acejavelin

That seems to work now, its almost like the permissions don't take on the sdcard, but once I moved it to /system/bin and chmod it, it worked fine... and you were right, I did have to su a couple command, but it appears to be working.

BTW, do you know where the dmesg log is kept? Usually it is in /var/log/dmesg but there is no /var in this device that I can't find it in /dev/logs either. Piping dmesg through tail -f just gives me the last lines of dmesg command output then it stops and doesn't keep the tail going... not terribly important, but would like to capture it just in case.


----------



## _bag_

You could always just do sh <SCRIPTNAME>. That will work regardless of it's permissions. Pretty sure they mount SD cards as no_exec, which prevents you from running executables on them. You could check by running mount in either adb shell or terminal emulator.


----------



## acejavelin

_bag_ said:


> You could always just do sh <SCRIPTNAME>. That will work regardless of it's permissions. Pretty sure they mount SD cards as no_exec, which prevents you from running executables on them. You could check by running mount in either adb shell or terminal emulator.


Putting it in /system/bin fixed that issue, now I am just trying to figure out how to log dmesg as well, and I can't the file that is logged in... normally it is in /var/log/dmesg but there is no /var in this device and I can't find it anywhere else. Using 'dmesg | tail -f > /sdcard/logs/dmesglog.txt' doesn't work, it only grabs the end of the output of dmesg and doesn't continue to monitor it... any idea what files(s) I can tail to get these messages?


----------



## _bag_

acejavelin said:


> Putting it in /system/bin fixed that issue, now I am just trying to figure out how to log dmesg as well, and I can't the file that is logged in... normally it is in /var/log/dmesg but there is no /var in this device and I can't find it anywhere else. Using 'dmesg | tail -f > /sdcard/logs/dmesglog.txt' doesn't work, it only grabs the end of the output of dmesg and doesn't continue to monitor it... any idea what files(s) I can tail to get these messages?


Tail can only keep reading if something is a file or named pipe, so tail really isn't useful without a dmesg.log. You could do:


Code:


<br />
while true; do<br />
	dmesg >> $dmesgOutputFile<br />
done<br />

where you define $dmesgOutputFile as your output file. (Technically you don't need the variable, but magic values are bad!)


----------



## acejavelin

_bag_ said:


> Tail can only keep reading if something is a file or named pipe, so tail really isn't useful without a dmesg.log. You could do:
> 
> 
> Code:
> 
> 
> <br />
> while true; do<br />
> dmesg >> $dmesgOutputFile<br />
> done<br />
> 
> where you define $dmesgOutputFile as your output file. (Technically you don't need the variable, but magic values are bad!)


So a simple script like this should keep logcat and dmesg dumping to sdcard:

_### logscript - capture logcat and dmesg output to /sdcard/logs/_

_su logcat >> /sdcard/logs/logcat.txt &_

_while true; do
dmesg >> /sdcard/logs/dmesg.txt
done_

And that should do it?


----------



## selyb

Usually external sd cards are formatted as fat/fat32 which do not support permissions. Since it is mounted as rfs (which IIRC does support permissions) it would not give an error trying to set permissions that simply do not stick.


----------



## acejavelin

selyb said:


> Usually external sd cards are formatted as fat/fat32 which do not support permissions. Since it is mounted as rfs (which IIRC does support permissions) it would not give an error trying to set permissions that simply do not stick.


Makes sense... seems to be the issue because pushing it into /system/bin and applying permissions worked fine. Thanks.


----------

