1

I created a script in which I login as a different user(superuser) during the execution of the script but the commands after this are put on hold until i logoff the other user. Is there any way that the script following the command to login(as superuser) shall continue executing in the new logged in user?

Prateek
  • 139
  • 1
  • 11

3 Answers3

1

You can run the script using nohup, which will run until the script is completed regardless of user log off.

nohup /path/to/script.sh

You can also run this in the background by using: nohup /path/to/script.sh &

http://linux.die.net/man/1/nohup

  • Hi,Thanks for your response. Actually The script is meant to login to an alias of the super user and perform some functions as superuser and stay there only , not to logout from the superuser shell. using nohup makes it to logout and return to the normal user shell – Prateek May 08 '14 at 11:08
1

Whatever commands you are executing after loging to superuser, just collect all them in on script file. And execute them with-

nohup script.sh &

nohup in combination with "&" will help you to exit superuser session immediately.

ShitalSavekar
  • 379
  • 2
  • 4
  • 10
  • Hi,Thanks for your response. Actually The script is meant to login to an alias of the super user and perform some functions as superuser and stay there only , not to logout from the superuser shell. using nohup makes it to logout and return to the normal user shell – Prateek May 08 '14 at 11:09
  • Have you tried "su root -c ". Here is my output. test1@AgentX:/var/log$ su root -c whoami Output:root – ShitalSavekar May 08 '14 at 13:15
  • Actually I am using dzdo command,not su or sudo.When dzdo is used with -u & -i, it allows us to login as a different user (not madatorily as a superuser), (in my case, it was a superuser). After i gave the command: dzdo -iu I got logged in as the other user but the script paused running after this because, it was a new shell/user completely & the script resumed itself as soon as i was logging off. I found a way, I can create a script in the superuser's directory & invoke that script through my local script using the command: dzdo -u Eg: dzdo -u newuser sh abc.sh – Prateek May 09 '14 at 03:55
0

Actually I am using dzdo command,not su or sudo.When dzdo is used with -u & -i, it allows us to login as a different user (not madatorily as a superuser), (in my case, it was a superuser). After i gave the command: dzdo -iu I got logged in as the other user but the script paused running after this because, it was a new shell/user completely & the script resumed itself as soon as i was logging off. I found a way, I can create a script in the superuser's directory & invoke that script through my local script using the command: dzdo -u Eg: dzdo -u newuser sh abc.sh

Prateek
  • 139
  • 1
  • 11