0

I have a couple of commands that need to be run from root

cd FolderName
sudo su
export VARIABLE_NAME=120
. install/setup.bash
ros2 run node node

I tried to create a script from these commands, but after the sudo su command, the script stops.
How can I run this set of commands under the root bash script?

DR.zarigan
  • 23
  • 1
  • 6
  • 1
    Re: "after the `sudo su` command, the script stops": I doubt this. Rather, what's happening is that the `sudo su` command is running, waiting for you to type commands for it to run as root. If you were to type `exit`, the `sudo su` command would complete, and then the rest of the script would run (but as you, not as `root`). – ruakh Aug 26 '19 at 06:25
  • Wouldn't `sudo su` wait for the user to enter `password` ? – han solo Aug 26 '19 at 07:05
  • @hansolo, I enter the password and after the script stops – DR.zarigan Aug 26 '19 at 09:07
  • No, it waits, just like @ruakh already told you. – tripleee Aug 26 '19 at 09:22

1 Answers1

0

The best way to do this, run the script as root user like,

$ cat install.bash
#!/bin/bash

cd FolderName
export VARIABLE_NAME=120
. install/setup.bash
ros2 run node node

And then run as root,

$ su root install.bash
han solo
  • 6,390
  • 1
  • 15
  • 19