I 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:
then save it somewhere, perhaps your home dir. ( /home/user/battery-script.sh )
Then make it executable, in terminal:
$ chmod +x /home/user/battery-script.sh
Now in terminal:
$ gksudo gedit /etc/rc.local
Now before the line
exit 0 write the path to your script. ( /home/user/battery-script.sh )
exit 0 is after everything else, or else it will exit before executing the commands.
Now just to be sure of when the script is run, you will probably want to add an xmessage command so that a message pops up when it is run.
xmessage -center "Battery script run in /etc/rc.local"
make sure it's before the
Now, reboot to test to make sure it runs on startup, then you can remove the xmessage line if it is satisfactory.
If this does not work for some reason, you can fall back to GNOME's autostart manager. It involves editing the sudoers file to allow root access to your script without a password. We will edit the file's permissions and ownership as to not create a security hole.
First, move the entire script into the /bin/ folder:
$ sudo mv battery-script.sh /bin/
set root ownership and permissions preventing a regular user from inserting malicious code to be run as root:
$ sudo chown root /bin/battery-script.sh
$ sudo chgrp root /bin/battery-script.sh
$ sudo chmod 555 /bin/battery-script.sh
Now that's set, time to edit the sudoers file:
$ gksudo gedit /etc/sudoers
Go to the bottom and add this line. Replace $USER with your username
$USER ALL = NOPASSWD:/bin/battery-script.sh
Now you can run the script without a password when using sudo.
Next, open Startup Applications, click add.
Put anything under Name, and under command put:
That's it! Your script will run as root when you boot up, you can add a line in the battery-script.sh
echo > /home/user/it_works.txt (replace with username) and that file will be created upon the next boot so you can be sure it's working, or as mentioned earlier, you can use xmessage.