Creating a script that will log into root and enter password and then run commands.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
You can login as root by disabling the display manager.
You can also configure the display manager to allow root logins.
Out of curiosity, why don't you just use a root terminal within the user environment or use the virtual terminals?
You can also try your commands under single user mode.
Last edited by Mr-Bisquit; 11-02-2009 at 02:26 PM.
You need to configure sudo correctly, to allow at least the commands you need. You can as well configure it so everyone can run anything as root just by doing "sudo <command>", then you can use "sudo <command>" in your script when it needs to run something as root.
You could as well run the whole script as root by using "sudo <script.sh>", in any case, the first step is learning how sudo works.
But, looking at your last post:
The script will sit on the pc and a remote pc will tell it to run when someone plugs a usb hdd into it.
What exactly do you need it to do? You might be able to do this with udev rules and no further complications.
Well, the basics of your script could be something like:
exit 1 # error
mount <whatever> || die "error while mounting"
rsync or cp or tar or <whatever else> || die "error while running rsync"
You can change the echo commands or pipe them to any mail sender, so the output is sent to wherever you want instead of being echoed locally which would do you no good.
This is one piece. The other piece is the trigger. If your system uses udev, you should check how to write udev rules, this can trigger events when a device is added or removed.
The firsts lines will name and set the right permissions for the device nodes when a device with the given properties is detected. The third one will create the mount points, the 4th will mount it, the last one will run your script. You could as well simplify the script and write everything as udev rules directly as well.
This is just an example, you will need to read the link above to write correct rules for your device, since the defining characteristics for each device will be different. This is just a general idea.