0

I need to run a sequence of command at the startup. This sequence require the root password as well. How can I do that?

This is in particular the sequence of command that I need to run:

virginia@asus-F552CL:~$ cd MT7630E_Wi-Fi_BT_Source_Release_20140625/rt2x00/
virginia@asus-F552CL:~/MT7630E_Wi-Fi_BT_Source_Release_20140625/rt2x00$ sudo su
[sudo] password for virginia: 
root@asus-F552CL:/home/virginia/MT7630E_Wi-Fi_BT_Source_Release_20140625/rt2x00# ./load.sh
root@asus-F552CL:/home/virginia/MT7630E_Wi-Fi_BT_Source_Release_20140625/rt2x00# exit
virginia@asus-F552CL:~/MT7630E_Wi-Fi_BT_Source_Release_20140625/rt2x00$ 
Donbeo
  • 501
  • 1
  • 8
  • 27

2 Answers2

0

Since you've mentioned having to do sudo su, I assume that you want these commands to be executed after login.

To do so, you'll have to put your commands in a script file, say, myCom.sh. The contents would look like below:

cd MT7630E_Wi-Fi_BT_Source_Release_20140625/rt2x00/
echo myPassword | sudo -S su && sudo su -c ./load.sh

Note that exit is not required as each command is run as root and script returns back after completion.

Also "myPassword" is to be provided in plain-text.

Then Use KDE/ Ubuntu's startup manager to start this script. Or you could place this file directly in ~/.profile.

On the other hand, if you want to run these commands on startup rather than login, you could use init scripts. You'll not have to use sudo su there as everything will run in root context.

user.dz
  • 48,105
Ashish
  • 963
  • 6
  • 13
0

You can modify your /etc/rc.local file that is executed as last service at run level startup sequence and it grants root permission.

Here is an example:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
cd /home/virginia/MT7630E_Wi-Fi_BT_Source_Release_20140625/rt2x00
/bin/bash load.sh
exit 0

Verify your change with this command:

sudo /etc/init.d/rc.local start

Please note the following points:

  1. load.sh will run as root
  2. the environment is restricted, so you may need to define missing variables
  3. if you want to log into syslog, use logger "message"

If is possible I suggest you to execute your script like this:

  /bin/bash /home/virginia/MT7630E_Wi-Fi_BT_Source_Release_20140625/rt2x00/load.sh

On Ubuntu runlevel start when filesystem and static-network-up event occurs. If you need to start load.sh at particular event, than is better define upstart task.

Lety
  • 6,039
  • 2
  • 29
  • 37