On 09-Nov-11 18:49:50, Peter Alcibiades wrote:
How do I change user in a script, and then carry on with the task at hand?
What I need to do is get the user to su to root, give the password of course, then carry on.
For instance:
su [and this then prompts for his password of course]
cd /home/fred/Desktop
[ now I would get him to enter a file name of a folder on his desktop and then...]
chown -R fred filename
What happens when I try this is that after changing accounts, the script stops.
Very basic question.........., sorry.
Peter
Interesting question! I played a bit, and found that one solution is to get the script, immediately after the "su", to invoke another script. Simple example: [A] The initial script, file testchr.sh, permissions 777 #!/bin/bash su -c /home/ted/Misc/whatdo.sh [B] The second script, file whatdo.sh, permissions 777 #!/bin/bash echo "Wow! I am" `whoami` [C] In action: ted@deb:~/Misc$ ./testchr.sh Password: Wow! I am root ted@deb:~/Misc$ whoami ted Note that it returns to the original user after the script finishes. Does this help? Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding@wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 09-Nov-11 Time: 19:24:00 ------------------------------ XFMail ------------------------------