last day (29 days later) » 

18:27
1
A: Creating scripts

MattI believe you can use the /etc/rc.local for a root boot script. First copy all the commands into a text file, then append this line at the top of the file: #!/bin/bash then save it somewhere, perhaps your home dir. ( /home/user/battery-script.sh ) Then make it executable, in terminal: $ ch...

could you put that on pastebin.com instead so the formatting shows correctly?
ah ok, sorry I use "[]" as parenthesis, so I did not mean to put them in the script. Now the question is do you get an xmessage alert when you reboot? If no, check it manually in the terminal to make sure it's installed. If yes, all you need to do is remove the brackets on the rc.local script.
basically type xmessage test to see if xmessage is installed. I thought it was installed by default, just making sure.
Also what Ubuntu version do you have? if you don't know do lsb_release -r in terminal
hm, I'm not sure why it isn't working.. could you paste the output of ls -l /etc/rc.local?
-rwxr-xr-x 1 root root 417 feb 26 18:45 /etc/rc.local.
U mean this?
yes. I looked into it a bit, and in short, please try this pastebin.com/tAGNfvQ2 for your rc.local; basically I'm hoping using the full paths of all commands will fix it. If not, then I do not know how to make rc.local work. however I do know of another way to make this work. Let me know.
18:27
Matt, the text doesnt show up! However if i check for the argument "cat /proc/sys/vm/dirty_writeback_centisecs" to see if the 3 command of the script works, it does say now 3000!That means that script probably executes and the problem is with the text command!
Oh ok.
well I'm glad it works.
You could try adding this line:

touch /home/emil/script_works.txt
It will create a file called script_works.txt and if you see that created, then rc.local is being executed.
hii
hi, lol
I was already writing up instructions for the other method
but since you don't need them I just wanted to point out, if you do not need root access, it is probably best to use "Startup applications"
It is part of GNOME, the desktop environment
ok, i added it ot rc file, i suppose it will create in the home folder?
yes as long as your home folder is /home/emil/
18:33
ok, gonna reboot, comin back
If you reboot and it is there, then it's all set
ok
Matt, there si definately smth going on with text , file wasnt created. here is rc file, pastebin.com/j09n5wPS. Want u to know that i appreciate ur help
r u sure about the commamńd?
I'm sure the command is supposed to work
but the environmental variables are supposedly different when the script is run, that's why I tried putting full paths
i think we can skip it, its not neccesseary if the text doesnt show, the script seems to be working...
The only thing, I'm thinking maybe the setting does persist across reboots
18:42
gonna check the parameter
well that's up to you, but I wouldn't be very confident if I could not get a confirmation message at boot
If you want I can quickly tell how to do the other method
sure! that would be great
it involves setting up sudo for using passwordless
and the startup applications in gnome
ok...
$ gksudo gedit /etc/sudoers
18:44
yes
emil ALL = NOPASSWD:/home/emil/battery-script.sh
Add that line to the bottom
then ctrl+S
done
should i reboot and see smth?
now go back to rc.local
$ gksudo gedit /etc/rc.local
ok
put a "#" before each line that you added, this makes the script ignore it [just disabling this part of it]
save it, now, copy the commands you want to keep
[copy the xmessage, and ifconfig command]
now edit the battery-script.sh
$ gedit battery-script.sh
paste in the commands at the bottom, and if you copied the "#" then remove them so they will be executed
[still with me here?]
[just one last step]
18:48
no yet,
matt, ifconfig is not in the script
i added it yesterday to disable ethernet
Ok that's fine
just copy the xmessage
btw did you leave echo 0 uncommented?
copies xmessage into script
which echo 0?
when I said to put "#" in front of everything
in /etc/rc.local
i got 300 and echo 10 in script
sorry I mean "exit 0"
exit not echo
18:52
so i put comment in fron of exit 0?
no, I meant you should leave that be
ok, its not touched
just comment [Or delete, you could just remove everything you put in] everything else
basically returning rc.local back to how it was
But ok, now, type this in:
sudo /home/emil/battery-script.sh
ok
did it work?
It didn't ask for a password right?
18:54
it didnt
text showed up
"sudo /home/emil/battery-script.sh"
no
i meant
battery script run in /etc...
thas what the popped up text shows
ok that's good
that means you can run it as root without a password
Now the last step is copying the last command ( sudo /home/emil/battery-script.sh ) into Startup applications
so what now? will the script work? should i delete cmmnt signs in rc file?
ok
search for "Startup"
when you open it, click Add
add script from home/emil
?
Name: boot script
Command: sudo /home/emil/battery-script.sh
you can name it whatever, just make sure the Command: is the same
And that's it!
18:58
Wow, awesome! does it mena i can forget RC file?
exactly
that's why I had you undo it
i still left to be executed sudo ifconfig to disable ethernet, is it ok?
you can do that, just do not put sudo
the script will be run as root
ifconfig eth0 down
hm i didnt know that one
you didn't know what?
19:00
that i can leave out sudo
but thanx matt! heading back to askubuntu to add reputation to u
you're welcome, glad I could help
after the next reboot, and you get the popup text, you can go back and remove the line
the xmessage line. because once you know it works you do not need it there, it would get annoying. lol
And also I will add this other solution to my answer
u mean i should take out of the script in Home/ Emil right?
correct
now I suppose I should mention that some people would consider this to be a security hole
yeah, it seems to be
Because right now, a script, editable by your user, will be run as root on every boot. If someone knew about it, they could add a line, and execute their own root commands, which is pretty close to giving them root without a password [as long as you're logged in]
If your account has a password, or if you are the only user, I would really not worry about it
you can fix that by easily setting ownership/permissions
I would recommend this:
sudo chown root battery-script.sh
sudo chmod 711 battery-script.sh
19:10
where do they go?
sets ownership to root so you must have root to edit it, and makes it so only root can read/write/execute, every other user can only execute
actually.. hold on
Let me make sure of the permission
ok
hmm...
I'm trying to make it so a script can only be executed but not changed by normal users
but it's not working, it keeps letting my normal user edit the script
:S
19:15
r u deploying the script weve been workin on?
No a simple echo script
Just to get permissions/ownership settled
[to patch the security hole]
was it actually neccassary to edit sudoers file?
yes
that's the only way to use sudo without password
so script wouldnt start ?
sudo will work regularly for every program, /except/ when you say "sudo ./battery-script"
Then it recognizes it in sudoers, and gives it root without a password
19:17
ahh ok
ohhhhhhhh
I figured it out
did u+
Since my test file [and also yours] is in your home directory, you own the file. the problem was it kept letting me edit a "root" file
Ok to fix the security hole, you need to move the script
oh ok, ill do it
I think...
19:23
thanx for the help again
yeah
:)
i'm still trying to make sure it's fixable
then I will give you the correct user/permissions
cool
Ok
You must move battery-script.sh to /bin/
do this
done, i geus i have to change path in start up now
$ sudo mv battery-script.sh /bin/
$ sudo chown root /bin/battery-script.sh
$ sudo chgrp root /bin/battery-script.sh
$ sudo chmod 555 /bin/battery-script.sh
$ gksudo gedit /etc/sudoers
Now replace /hom/emil/ with /bin/
So it should be
emil ALL = NOPASSWD:/bin/battery-script.sh
19:29
ok done
)
ok, matt, i have to go, thanx for the help
Then a regular user may no longer edit the script at will
[and possibly do some mischief as root] :P
[sorry my laptop b0rked, had to reboot]
but now I will put all of this into the original answer as an alternative
19:49
Ok, all done

  last day (29 days later) »