PDA

View Full Version : help with making a script


felbutss
2010-03-04, 20:57
hey guys i did a search before posting but havent been able to find anything.

well i have this bug https://bugs.maemo.org/show_bug.cgi?id=8723
every day i have to run the following command in xterminal to stop my n900 from not responding

sudo gainroot
killall hildon-desktop
killall hildon-home

im wondering how i can make it into a simple script and have a shortcut on the desktop?????

sorry. any help would be good im still learning and love it :)

daperl
2010-03-04, 21:48
Whoa, that sucks.

Yes, I should be able to help, but you caught me at the worst possible time. If no one helps you within the next 24 hours I should be able to cook something up for you by then. In the meantime, here's a link that show an exec of a command line call (http://talk.maemo.org/showthread.php?p=367773) and here's (http://talk.maemo.org/showthread.php?t=42499) a very simple example of a desktop (home) applet. You need to add a widget that will signal your command line calls. Also, you probably need to open up your /etc/sudoers to allow "user" some more power.

Good luck!

felbutss
2010-03-04, 22:59
hey. im still a little confused. im a pro with microsoft but still learning linux


i need something like a bat/shell file. i want to be able to install it then add a shortcut to the desktop.

can someone make it for me please? i also want to see how you did it and what i do next. still learning


any help??

felbutss
2010-03-05, 01:48
anyone? is it that hard? :S

daperl
2010-03-05, 17:30
Copy and paste the following into a file called:

/home/user/killerapp.sh

#! /bin/sh

/usr/bin/sudo /usr/sbin/gainroot
/usr/bin/killall hildon-desktop
/usr/bin/killall hildon-home

Then, from a terminal, run the command:

chmod 777 /home/user/killerapp.sh

As root, copy and paste the following into a file called:

/usr/share/applications/hildon/killerapp.desktop

[Desktop Entry]
Type=Application
Name=App Killer
Exec=/usr/bin/osso-xterm /home/user/killerapp.sh

Now, got to the application manager. Be patient while it quickly updates itself. Then, go to the last page and verify that "App Killer" exists.

Add "App Killer" as a desktop shortcut.

Matan
2010-03-05, 18:04
It does not work like this. The killall commands after the sudo command will not run as root.

But it should not be a problem, since hildon-home and hildon-desktop run as user, so there should not be a problem to run those commands as user as well.

daperl
2010-03-05, 18:59
It does not work like this. The killall commands after the sudo command will not run as root.

But it should not be a problem, since hildon-home and hildon-desktop run as user, so there should not be a problem to run those commands as user as well.

Are you saying that

#! /bin/sh

/usr/bin/killall hildon-desktop
/usr/bin/killall hildon-home

would do what he wants it to do?

EDIT: Changed it in the above script.

Also, if he's not root, would he need a -9?

felbutss
2010-03-06, 00:51
thanks so much guys. ill have a play with it tonight :D. i want to try a few things with scripts. how do i run scripts as root though?

daperl
2010-03-06, 02:51
thanks so much guys. ill have a play with it tonight :D. i want to try a few things with scripts. how do i run scripts as root though?

I'm not sure if this is the best advice, but if, as root, you add the following line to

/etc/sudoers

user ALL = NOPASSWD: ALL

you should be able to run anything as root by putting

sudo

in front of it. For instance,

sudo whoami

should output "root" and not "user."

felbutss
2010-03-06, 17:07
quick question. how do i set a icon??? sorry to break balls

felbutss
2010-03-06, 17:14
I'm not sure if this is the best advice, but if, as root, you add the following line to

/etc/sudoers

user ALL = NOPASSWD: ALL

you should be able to run anything as root by putting

sudo

in front of it. For instance,

sudo whoami

should output "root" and not "user."


i missed this step. how do i apply this to the above tutorial you made???

Big Phat Jan
2010-03-06, 17:23
I'm not sure if this is the best advice, but if, as root, you add the following line to

/etc/sudoers

user ALL = NOPASSWD: ALL

you should be able to run anything as root by putting

sudo

in front of it. For instance,

sudo whoami

should output "root" and not "user."

You should be careful when editing the sudoers file. If you make a mistake with the syntax sudo will stop working entirely.

You can protect against this somewhat be using the "visudo" command. This will test for parse errors when you try to save and potentially save some pain.

Though I guess it should be obvious, it might be worth noting that the above edit is probably not a good idea on a proper multi-user system!

Cheers,
Jan

Big Phat Jan
2010-03-06, 17:26
i missed this step. how do i apply this to the above tutorial you made???

If Matan is correct (and I'm sure he is!) you do not need this step at all. It would have been useful if you needed to be root to kill the processes you were trying to kill, but as it seems that you don't I would leave it alone.

quick question. how do i set a icon??? sorry to break balls

I think you just add a line to your .desktop file like this: "Icon=/path/to/icon". You might not see the result until you restart though.

Cheers,
Jan

felbutss
2010-03-06, 17:29
ok ill just do it without it :D but lol one thing guys. why isnt it showing up in the app manager???? i verified all the steps 100%

Big Phat Jan
2010-03-06, 17:35
ok ill just do it without it :D but lol one thing guys. why isnt it showing up in the app manager???? i verified all the steps 100%

I think that you wouldn't expect to. Look in the menu, you should see it there. You can add it as a shortcut to your desktop as you would any other program.

Cheers,
Jan

felbutss
2010-03-06, 17:40
OMG IT WORKED. thanks for the help. hope to return the favor one day

'had one problem because i had one letter as caps lol'


this is so fun. im making it speak after its finished. i feel like a kid again

daperl
2010-03-06, 18:30
quick question. how do i set a icon??? sorry to break balls

I can't tell if you got this working or not. I'm not exactly sure how all this stuff works, but here's something that always seems to work for me:

Create a 48x48 .png file and call it killerapp.png. Put it in:

/usr/share/pixmaps

Inside:

/usr/share/applications/hildon/killerapp.desktop

add the line

Icon: killerapp

I'm not sure, but you might have to reboot to see the icon in the Application Manager and/or on the Desktop. If you're not seeing it on the Desktop, you might have to delete and readd the shortcut.

kd_alex
2010-03-16, 19:47
Since you all seem to be wise in writing scripts I was hoping to ask for help with one of mine. Sorry to Hijack this thread but it seems the appropriate place to post my question.

In my script I want to execute a command that requires root permissions.

so my script looks like this

#!/bin/sh
sudo gainroot
echo `/etc/init.d/lirc start`
exit

The problem is my script hangs on trying to sudo gainroot. I have also tried this using echo `sudo gainroot`

Any suggestions?

Matan
2010-03-16, 19:51
A shell script is not like typing the same characters at a shell. What you want can be achieved by

sudo echo `/etc/init.d/lirc start`

Assuming you set /etc/sudoers to allow execution of echo as root.

kd_alex
2010-03-17, 03:47
thank you so much for the suggestion.

when searching sudoers i found that '/etc/init.d/lirc start' was included already for all users with no password. so i modified what you suggested to

echo 'sudo /etc/init.d/lirc start'

it worked perfect. now to save it as a shortcut for the desktop

again thanks.