Running scripts directily (without write "sh" before) - General Questions and Answers

Hi,
I have a problem executing one script.
I put my script as /system/bin/toleinit with 775 permissions:
Code:
# ls -l /system/bin/toleinit
ls -l /system/bin/toleinit
-rwxrwxr-x root root 373 2010-03-22 02:17 toleinit
Well, when I try to run this script I get a "not found" error:
Code:
# /system/bin/toleinit
/system/bin/toleinit
/system/bin/toleinit: not found
If I run it with "sh" the script works fine:
Code:
# sh /system/bin/toleinit
sh /system/bin/toleinit
+++ Wellcome to toleinit Script
How to run the script directly? (without write "sh" before)
The same error occurs when I run "busybox run-parts dirname", I get a "not found" error for each script file in the directory.
Thanks in advance.

write this on the very first line of your script :
#!/bin/sh
Click to expand...
Click to collapse

The first line is:
Code:
#!/system/bin/sh
I think that is correct. or not?

Argh!!
The problem is solved when I save the script file in UTF-8 and not ANSI. Now I can run the script without problems.
Thanks anyway.

Related

Android sh script error "[: not found" (UTF8? ANSI? Windows? linux?)

I'm getting crazy ...
I have problems running this script, saved as /system/etc/tole.d/10sdcard:
Code:
#!/system/bin/sh
echo "+++ tolemaC 10sdcard";
if [ -e /dev/block/mmcblk0p2 ];
then
echo "+++ Mounting second SD partition on `getprop tole.sd2.path`";
/system/bin/busybox mount /dev/block/mmcblk0p2 /sdcard2;
fi;
Fist I wrote the script on windows using Notepad++, I saved the script as ANSI and I got this error:
Code:
# /system/etc/tole.d/10sdcard
/system/etc/tole.d/10sdcard
/system/etc/tole.d/10sdcard: not found
Then I saved the script using notepad++ as UTF-8, then I got this error:
Code:
# /system/etc/tole.d/10sdcard
/system/etc/tole.d/10sdcard
: not found/tole.d/10sdcard: ´╗┐#!/system/bin/sh
: not found
+++ Mounting second SD partition on /sdcard2
: not found
: not found
/system/etc/tole.d/10sdcard: 13: Syntax error: "fi" unexpected (expecting "then")
Appears some chars at the begining of first line.
Then I have saved the script on Linux using GEdit as UTF-8 and then I get this:
Code:
# /system/etc/tole.d/10sdcard
/system/etc/tole.d/10sdcard
+++ tolemaC 10sdcard
[: not found
It seems that the script now reads well but I don´t know what is wrong.
¿There is something wrong in the script?
¿any ideas?
Thanks in advance.
Solved!
I have found the way (for me)
I have to create the files as ANSI and saved as unix file.
Notepad++ have options for it.
Wanna just say thanks, I was wondering why my scripts weren't working
Thanks!

[Q] adb shell in batch

Hi,
I'm making a batch file (*.bat) for myself to try make some things easier file where I enter commands with adb.exe.
The problem is, any code after 'adb shell' is not executed in the batch.
So if I had a batch with the following:
Code:
adb shell
su
'su' will not be executed and stays at '$'.
It seems like it's too deep for a batch file to enter codes.
I also tried pushing a sh with the same script and run it from adb but then all I get it permission denied.
I have also tried 'adb shell su' without any luck.
Anyone with a solution?
Anyone? Or how about a .rc file that gets su and runs commands...
Sent from my HTC
To execute a script, you can always push your script and then execute it:
Code:
adb push script /sdcard/script
adb shell sh /sdcard/script
As for the commands you have shown, keep in mind that su doesn't simply change the running shell's permissions or the like but creates a new child environment within its own shell. You leave your script and after the new shell has finished, you're back in your old environment and the script continues.
mizch said:
To execute a script, you can always push your script and then execute it:
Code:
adb push script /sdcard/script
adb shell sh /sdcard/script
As for the commands you have shown, keep in mind that su doesn't simply change the running shell's permissions or the like but creates a new child environment within its own shell. You leave your script and after the new shell has finished, you're back in your old environment and the script continues.
Click to expand...
Click to collapse
yes, is there any way to automate the script inside the shell and use exit to finally go back to the batch script.
Can you provide me with an example of what you want to achieve?
To execute shell commands from a batch, it doesn't matter if I have to push a script and execute it. It's so that I get su and automate commands after that. Like flash_image, remount, chmod etc..
you will need to use the 'adb shell command' ad 'sh' files
I am trying to create a unix script file that copies files from /dbdata/databases to another folder as a backup.
When I try running the script in adb shell as SU, I get
cd: can't cd to /dbdata/databases
This is on a rooted Captivate. Any help would be greatly appreciated!
Hi,
su -c "command" should do the job for you. You will need to enclose the whole of the command in quotes however, otherwise su will be expecting the command to execute, doing nothing.
Example: adb shell "su -c 'sqlite3 /data/data/my.db/databases/mydb.db < /sdcard/dump.sql'" (run from a Unix or Windows(?) shell). Notice the use of "" and ''.
(in this case dump.sql contains .dump, for instance)
Of course the sqlite3 command could be placed within another script on the android device.
Hope that helps.
I looked around a bit and found the answer.
The simple answer is, wrap the command
Code:
cp "source" "destination"
in double quotes!
Thank you grindingbob for the adb shell "su -c 'sh /mnt/sdcard/tmp/2.sh'" command.
No probs I was more referring to executing commands as a su without interacting with adb shell.
As a side-note, cp might not be a good idea, unless you're sure no db accessing is taking place at the same time.
I am pretty sure well as sure as a novice can be! The files I am backing up are log files, call history and text message history.
The results from running a unix script which contains
Code:
cp "/dbdata/databases/com.android.providers.contacts/contacts2.db" "/mnt/sdcard/tmp4/contacts2.db"
cp "/dbdata/databases/com.android.providers.telephony/mmssms.db" "/mnt/sdcard/tmp4/mmssms.db"
cp "/dbdata/databases/com.sec.android.provider.logsprovider/logs.db" "/mnt/sdcard/tmp4/logs.db"
are only the logs.db file is copied, the other two are not.
grindingbob said:
No probs I was more referring to executing commands as a su without interacting with adb shell.
As a side-note, cp might not be a good idea, unless you're sure no db accessing is taking place at the same time.
Click to expand...
Click to collapse
Permission issues for *.sh files from ADB
Dear All,
I have a 3.2 device with Root permissions & Busybox.
I created a sample *.sh file, Pushed to SDcard, and gave '777' Permissions. When i Try to run it from ADB shell its not working Any help...
CMD prompt Traces:
Step -1: Created a sh file
cat TAB.sh
#!/bin/sh
cd /data/data/com.android.gallery/shared_prefs
Step -2 Pushed the file to SDcard
# ls -l *.sh
ls -l *.sh
-rw-rw-r-- root sdcard_rw 56 2012-03-13 15:06 SP.sh
-rw-rw-r-- root sdcard_rw 62 2012-03-13 15:05 TAB.sh
Step -3 Gave 777 permission for *.sh files
# chmod 777 *.sh
chmod 777 *.sh
# ls -l
ls -l
-rw-rw-r-- root sdcard_rw 56 2012-03-13 15:06 SP.sh
-rw-rw-r-- root sdcard_rw 62 2012-03-13 15:05 TAB.sh
Execute permission not applied
Tried other operations, dint workout
Step 4 other options:
# chmod +X *.sh
chmod +X *.sh
Bad mode
# chmod +x *.sh
chmod +x *.sh
Bad mode
# chmod u+x *.sh
chmod u+x *.sh
Bad mode
Any Help?

[Q] Disable proximity sensor via terminal emulator

Hi @ all,
I have that following problem: My phones display turns off automatically while im receiving or doing a call. My proximity sensor is broken and i would like disable it and i found a good solution here in this formus:
http://forum.xda-developers.com/showthread.php?t=925814&page=5
# cd /data/local
# touch userinit.sh
# echo "#!/system/bin/sh" > userinit.sh
# echo "#" >> userinit.sh
# echo "chmod 0000 /dev/cm3602" >> userinit.sh
# echo "chmod 000 /dev/cm3602" >> userinit.sh
# chmod 777 userinit.sh
But there's a little problem. I'm not well in programming - now my question is: can someone cange the code that it fit's to my phone. It's a Desire S with CyanogenMod 10 Beta.
Would be very thankful!
our phone has a /dev/cm3602 as well, so it probably uses the same chip.
note: the following is untested
Code:
cat>/etc/init.d/98-disable-sensor<<EOF
#`which sh`
chmod 000 /dev/cm3602
EOF
run that through adb shell and if your kernel has init.d support it will automatically disable your proximity sensor every boot. disable the sensor for your current session by running a simple 'chmod 000 /dev/cm3602' through adb shell.
THX! I will try it out soon.
Sent from my Desire S using xda app-developers app
I've just figured out that those commands won't work as is -- I stupidly forgot you need to remount system r/w and make the file executable for it to run. This should work (still didn't test it) -- run it all in an adb shell:
Code:
mount -o remount,rw /system
cat>/etc/init.d/98-disable-sensor<<EOF
#!`which sh`
chmod 000 /dev/cm3602
EOF
chmod 755 /etc/init.d/98-disable-sensor
mount -o remount,ro /system
i just tried it out and it says
[email protected]:/ # mount -o remount,rw /system
mount -o remount,rw /system
[email protected]:/ # cat>/etc/init.d/98-disable-sensor<<EOF
cat>/etc/init.d/98-disable-sensor<<EOF
> #!'which sh'
#!'which sh'
> chmod 000 /dev/cm3602
chmod 000 /dev/cm3602
> EOF
EOF
sh: can't create temporary file /sqlite_stmt_journals/mksh.vXIer13043: No such file or directory
but simply 'chmod 000 /dev/cm3602' works fine for one session! thanks!
Ooh, joy, it's that bug in the android shell that I'd forgotten about.
Try this instead:
In an adb shell, run 'which sh'. Note the path it returns.
On your computer, copy the following to a text file named '98-disable-sensor'. Be sure to use an editor (e.g. Notepad++) that can save with LF newline bytes and make sure you tell it to do that! (Under Windows, a newline is marked by the bytes \r\n, which is wrong for Linux - it should be just \n. Save the file as 'Unix text file' or something like that when asked.)
Code:
#!/path/to/sh/you/wrote/down/earlier
chmod 000 /dev/cm3602
Push it to your device: 'adb remount' + 'adb push 98-disable-sensor /etc/init.d/'
Make it executable: 'adb shell chmod 755 /etc/init.d/98-disable-sensor'
Remount system r/o again: 'adb shell mount -o remount,ro /system'
Aquous said:
Ooh, joy, it's that bug in the android shell that I'd forgotten about.
Try this instead:
In an adb shell, run 'which sh'. Note the path it returns.
On your computer, copy the following to a text file named '98-disable-sensor'. Be sure to use an editor (e.g. Notepad++) that can save with LF newline bytes and make sure you tell it to do that! (Under Windows, a newline is marked by the bytes \r\n, which is wrong for Linux - it should be just \n. Save the file as 'Unix text file' or something like that when asked.)
Code:
#!/path/to/sh/you/wrote/down/earlier
chmod 000 /dev/cm3602
Push it to your device: 'adb remount' + 'adb push 98-disable-sensor /etc/init.d/'
Make it executable: 'adb shell chmod 755 /etc/init.d/98-disable-sensor'
Remount system r/o again: 'adb shell mount -o remount,ro /system'
Click to expand...
Click to collapse
Hi
Do you know what is the command to turn off all sensors ?
i want to execute the command when screen is off (by xposed edge)
and turn on again when screen is on
loopypalm said:
Hi
Do you know what is the command to turn off all sensors ?
i want to execute the command when screen is off (by xposed edge)
and turn on again when screen is on
Click to expand...
Click to collapse
I use the below command on low battery trigger via Tasker
Code:
cmd statusbar click-tile com.android.settings/.development.qstile.DevelopmentTiles\$SensorsOff
varunpilankar said:
I use the below command on low battery trigger via Tasker
Code:
cmd statusbar click-tile com.android.settings/.development.qstile.DevelopmentTiles\$SensorsOff
Click to expand...
Click to collapse
Thx but i don't want to use tasker or any extra app
loopypalm said:
Thx but i don't want to use tasker or any extra app
Click to expand...
Click to collapse
Us can use the via adb or shell script event trigger.
varunpilankar said:
Us can use the via adb or shell script event trigger.
Click to expand...
Click to collapse
what is the adb comand ?
loopypalm said:
what is the adb comand ?
Click to expand...
Click to collapse
Code:
adb shell cmd statusbar click-tile com.android.settings/.development.qstile.DevelopmentTiles\$SensorsOff
varunpilankar said:
Code:
adb shell cmd statusbar click-tile com.android.settings/.development.qstile.DevelopmentTiles\$SensorsOff
Click to expand...
Click to collapse
it work on PC but no luck in terminal/xposed edge
Edit : i found a way !
replace "adb shell" with "#!/bin/sh" work
If you have root then you can use Su directly
varunpilankar said:
If you have root then you can use Su directly
Click to expand...
Click to collapse
and the comand is ?
terminal - type
su
cmd statusbar click-tile com.android.settings/.development.qstile.DevelopmentTiles\$SensorsOff

[Q] Nabi XD root

So I have been working on rooting for the Nabi XD. Specifically to grab a dd of mmcblk0p1 and p2 so I can extract kernel and ramdisk to build a TWRP.
The 2 options I have tried are 1) Bin4ry root many Android, 2) Build TWRP based off the different Nabi2 kernel to gain access to /system
Bin4ry exploit fails with mount: Permission denied, when attempting to remount rw with busybox. The device is 4.1.1 so they must have patched it or cherry picked a patch. The build was this year.
The TWRP will boot but with a blank screen. Comparing the config.gz for kernel builds explains the blank screen. ADB is however is up and running, but the internal storage is not seen as a block device. cat proc/partitions is blank.
The third thing of interest is that there is a bin in xbin called su2. su2 -v yields an output of 3.3.
Code:
[email protected]:/system/xbin $ su2 -v
su2 -v
3.3
[email protected]:/system/xbin $ su2 -help
su2 -help
Usage: su [options] [--] [-] [LOGIN] [--] [args...]
Options:
-c, --command COMMAND pass COMMAND to the invoked shell
-h, --help display this help message and exit
-, -l, --login pretend the shell to be a login shell
-m, -p,
--preserve-environment do not change environment variables
-s, --shell SHELL use SHELL instead of the default /system/bin/sh
-v, --version display version number and exit
-V display version code and exit,
this is used almost exclusively by Superuser.apk
[email protected]:/system/xbin $ ls -l su2
-rwxr-xr-x root shell 91728 2013-02-02 07:03 su2
How can I put this to use? Just running su2 over adb results in nothing, and through Term.apk as permission denied. I obviously need the associated Superuser.apk to grant access, but it seems hardcoded to look for su. I looked through the source to see if I could recompile to look for su2, but I don't know if it's as simple as that.
Any thoughts?
Strange they left the su binary there.
But first : show me a "ls -l su2", we need to see if it has correct permissions or if it is just there and cannot do anything
Second: just try "su2 -c /system/bin/sh", if you are lucky it starts a rootshell.
Regards
I thought it was weird too that is was left behind, and hopefully an easy way to even gain temp root. If I can just dd the boot partition it's smooth sailing.
[email protected]:/system/xbin $ ls -l su2
-rwxr-xr-x root shell 91728 2013-02-02 07:03 su2
No setuid bit set? Should be -rwsr-sr-x?
I tried the second thing via adb. It just echos the command and prompt stays $. Using something like Term.apk yields permission denied. Tried different quotes for passing -c. Any symlinking tricks?
[email protected]:/system/xbin $ su2 -c /system/bin/sh
su2 -c /system/bin/sh
1|[email protected]:/system/xbin $ su2 -c '/system/bin/sh'
su2 -c '/system/bin/sh'
1|[email protected]:/system/xbin $ su2 -c "/system/bin/sh"
su2 -c "/system/bin/sh"
1|[email protected]:/system/xbin $

busybox ls --color and many other commands "Working"

have you got bored of your one Text colored terminal ?
when you look at the results you always are confused ?
well .. you came into the right thread
I'm here today to show you how to make every busybox command fully functional
I was trying to make this command work but no success
Code:
#ls --color=always
then i ended up making busybox fully functional
Note: you must have rooted device and custom recovery and SDK tools " incase you don't have adb.rar "and your phone developer mode and USB debugging checked .
go to your SDK tools press sheft and right mouse click and open cmd here
________________________________________________________________________
now .. lets get to it shall we ?
1 - reboot into recovery and connect your device in your PC
2 - type in these commands in your PC command prompt you opened in order :
Code:
# adb shell
# mount system
# cp /system/bin/sh /sdcard/Download/sh
#adb reboot
3 - reboot your device
4 - download this busybox app and start it
jrummy.busybox.installer
5 - you'll see in the app's INSTALLER icon a location /system/xbin
change it to /system/bin
6 - open app's settings "upper right corner beside the three dot's" and check all what's in the installer settings
7 - press back and click install " your phone will boot into recovery and install the busybox "
8 - after finishing the process your device will reboot normally but wait a minute !!! SU is not working anymore :crying:
9 - reboot your device again into recovery !! " I'll try to fix it for you "
10 - type in these commands in order :
Code:
#adb shell
#mount system
#cp /sdcard/Download/sh /system/bin/sh
#chmod 755 /system/bin/sh
#adb reboot
and we are done
look at the attachment below this is how your terminal will look like and error free
I'm sorry about this post
apparently I was kinda mistaken
I think what happens that lead to this is
when you write down the applet's name in terminal the device start to search inside bin file first .. if the applet was not found in bin .
the device will start to search on xbin file and maybe the whole storage for that command
so .. since there are some applets in bin are the same one in busybox and I was able to locate them "took me like an hour to do so"
and these applets are :
Code:
[COLOR="blue"]blkid
brctl
cat
chmod
chown
clear
cmp
cp
date
dd
df
dmesg
du
grep
gzip
hd
id
ifconfig
insmod
ionice
ip
kill
ln
ls
lsmod
lsof
mkdir
mke2fs
mknod
mkswap
mount
mv
netstat
nohup
ping
ping6
printenv
ps
readlink
reboot
renice
rm
rmdir
rmmod
route
sh
sleep
swapoff
swapon
sync
top
touch
tune2fs
umount
uptime[/COLOR]
there are a lot of difference in results between the factory applets and the busybox applets
if you want to see the difference install busybox in /system/xbin and in terminal type one of these applets above like this :
for busybox applets result :
Code:
busybox [I][COLOR="blue"]applet[/COLOR][/I]
for system applets result :
Code:
[I][COLOR="Blue"]applet[/COLOR][/I]
it might not be a new thing but for me it is
I just wanted to share that info for the ones who doesn't know
Edit : there is also one applet in system/xbin which is " nc "
thanks .

Categories

Resources