Run multiple commands in linux without logging as root user?

649 views Asked by At

I want to write a script, i want to run from non-root user, the script contains multiple commands.

For EX: 
sudo -i
hostname
df -h

I tried the same 3 commands in a script but it's logging to root user and not executing hostname and df -h command.

1

There are 1 answers

2
lukaszbob On

If you want to run command with root privileges use

sudo command,

command

 sudo -i

will log you to root's shell. If you want to run multiple commands you should use

command1 && command2

it runs command2 after command1 is sucesuflly finished.

If you need root's privileges in your script maybe you should use sudo when executing your script, and in your script check if user has necessary privileges (http://www.cyberciti.biz/tips/shell-root-user-check-script.html).