maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   A equivilent of a .bat file on the n900? (https://talk.maemo.org/showthread.php?t=39165)

LozBlake 2010-01-03 22:43

A equivilent of a .bat file on the n900?
 
I'm a bit of a linux noob so bear with me.

Basically i wonder if theres a way i can store two commands for x terminal and store them in a file which i could just open and it would execute the commands for me, like how .bat files do with command prompt in windows.

This would make my life much easier as i can't find a way to copy and paste in x terminal.

sudo gainroot;
echo 118 > /sys/class/i2c-adapter/i2c-2/2-0063/power_level;

This is what i'd like to do, a solution like this would save me lots of tedious typing every car journey

CrashandDie 2010-01-03 22:47

Re: A equivilent of a .bat file on the n900
 
Code:

echo "#!/bin/bash" > powerlevel.sh
echo "sudo gainroot; echo 118 > /sys/class/i2c-adapter/i2c-2/2-0063/powerlevel;" >> powerlevel.sh
chmod +x powerlevel.sh


Z0l 2010-01-03 22:52

Re: A equivilent of a .bat file on the n900
 
Pretty good, 2 small things:
-there is no bash in the default install, and i'm not sure if the symlink exists, so please change the first line to "#!/bin/sh"
-you forgot to mention, that the script can be run by issuing the following command from the x terminal:
./powerlevel.sh

LozBlake 2010-01-03 22:59

Re: A equivilent of a .bat file on the n900
 
thanks guys for your quick replies. this looks like what i would need, so just to check, do i type the code as crashanddue posted in x terminal and it will create the file, and then to run i just need to type ./powerlevel.sh as zio said?

Z0l 2010-01-03 23:02

Re: A equivilent of a .bat file on the n900
 
Yes, you type in this in X Terminal:
Code:

echo "#!/bin/sh" > powerlevel.sh
echo "sudo gainroot; echo 118 > /sys/class/i2c-adapter/i2c-2/2-0063/powerlevel;" >> powerlevel.sh
chmod +x powerlevel.sh

after this, you can run it anytime by typing this
Code:

./powerlevel.sh

qwerty12 2010-01-03 23:04

Re: A equivilent of a .bat file on the n900
 
Code:

#!/bin/sh

echo "echo 118 > /sys/class/i2c-adapter/i2c-2/2-0063/power_level" | sudo gainroot

Be sure to chmod +x. The echo into sudo gainroot is important - or, otherwise, it'll try echoing into power_level as user, not as root.

LozBlake 2010-01-03 23:14

Re: A equivilent of a .bat file on the n900
 
I think i have this problem, i have write the script as written above amd made the change zoi said, it works fine when i run it when i'm already root in xterm however it doesn't change the powerlevel if i run it as user, even though the sudo root command is in there, all it does is give me root access.

Any ideas what i need to change?

qwerty12 2010-01-03 23:20

Re: A equivilent of a .bat file on the n900
 
Quote:

Originally Posted by LozBlake (Post 451787)
I think i have this problem, i have write the script as written above amd made the change zoi said, it works fine when i run it when i'm already root in xterm however it doesn't change the powerlevel if i run it as user, even though the sudo root command is in there, all it does is give me root access.

Any ideas what i need to change?

http://talk.maemo.org/showpost.php?p=451774&postcount=6

RWFarley 2010-01-03 23:28

Re: A equivilent of a .bat file on the n900
 
is the problem that it should be entered as one line? My browser splits the part after the pipe onto a new line.

texaslabrat 2010-01-03 23:31

Re: A equivilent of a .bat file on the n900
 
Quote:

Originally Posted by LozBlake (Post 451787)
I think i have this problem, i have write the script as written above amd made the change zoi said, it works fine when i run it when i'm already root in xterm however it doesn't change the powerlevel if i run it as user, even though the sudo root command is in there, all it does is give me root access.

Any ideas what i need to change?

You can't use sudo like that...the "sudo gainroot" launches a new shell process but the next command in your script executes in the exiting "user"-owned shell. It's not a hard problem to fix in a "normal" linux distro (I typically use "su" with flags to switch users inside a script) but I'm not sure how you would do it with the seemingly unique way that the root account and user account are related in maemo. On the surface it would seem as though you could simply issue a "sudo ./myscript" but I don't think that works out of the box in maemo. Hopefully some of the more seasoned maemo veterans will have an answer for the on-liner you are seeking to create.

One thing you *might* try is to setuid the script (chown file to root, and then chmod u+s the file) that does the things you want to do. You would then execute it as "user" but it would automagically run as root. Can provide a nice huge security hole in most unix systems, but with the "sudo gainroot" thing that doesn't even require a password, I'm not sure that's a concern in this particular case.


All times are GMT. The time now is 10:33.

vBulletin® Version 3.8.8