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.
If you want to run command with root privileges use
command
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).