0

My knowledge of Linux is on the pre-school level and most of the answers I've found here - it didn't answer my problem.

I want to automate my everyday job and put the process of logging into the root user, doing some lines and logging out. E.g.

#!/usr/bin/bash
cd /
su -
echo "my_password"

Here is a problem I need to confirm the password by pressing the ENTER key

doing something as root

logout

I tried:

echo "my_password" | su

But it didn't help and also tried

su - echo "my_password\n"

It didn't help either and also tried

su - echo -e "my_password\n"

It was wrong and also tried

su - echo "my_password" bind '\C-m'

It was wrong either. What is the easiest way to do that? Thanks,

Varun Jain
  • 1,371
  • 12
  • 26
andre
  • 1
  • Do you want to make a script to automate some task? – A.Villegas Jan 23 '20 at 18:19
  • Look into `sudo` and this answer https://askubuntu.com/a/147265/140035 – jamieguinan Jan 23 '20 at 18:23
  • Please have look at: https://unix.stackexchange.com/questions/115758/how-to-login-as-root-from-bash-and-do-stuff – j03d03 Jan 23 '20 at 18:24
  • Yes, to use one file started by doubleclick mouse button, instead of typing all lines in command line... – andre Jan 23 '20 at 18:26
  • 1
    Putting your password in a script file is a terrible idea, especially if that password has `sudo` privileges. A much better solution is to give *quite restricted* passwordless access to one or two very specific local scripts. – tripleee Jan 23 '20 at 18:28
  • It's used by everybody in the room when we work on centos7 and in local area without access to net. I could add a new user with superuser rights but the disk space is small and it would exceed the quota, the safety issue is not important in this case – andre Jan 23 '20 at 18:38

0 Answers0