SUDO commands

Discussion and support for all Linux distributions and Unix flavours (FreeBSD, OpenBSD, etc).
Post Reply
Damina
Registered User
Posts: 42
Joined: 06 Sep 2005, 02:00
Contact:

SUDO commands

Post by Damina »

Is there a way to run a command with sudo, and include your password for the prompt that appears?
This is usually how I do it via command line:

Code: Select all

[daminassad@oracle]$ sudo rm file1.txt
Password:
I'm trying to create a shell script that runs a command with sudo, but the password prompt from the server isn't acknowledged. so what i'm looking for is a way to inlclude the password in the command to bypass having to enter my password. Or is there perhaps a way to expect the password prompt?

Changing the ownership of the file to root doesn't help.
Richard_
Registered User
Posts: 2295
Joined: 18 May 2003, 02:00
Location: Durban, South Africa

Post by Richard_ »

Code: Select all

echo "YourPasswordHere" | sudo -S YourLinuxCommand
Damina
Registered User
Posts: 42
Joined: 06 Sep 2005, 02:00
Contact:

Post by Damina »

Excellent!

Thanks a lot, it works perfectly.
AlphA
Registered User
Posts: 3213
Joined: 15 Mar 2005, 02:00
Location: JHB
Contact:

Post by AlphA »

Thanks Richard - I didnt know one could do thats -S thing.....

:thumbsup:
Image
Richard_
Registered User
Posts: 2295
Joined: 18 May 2003, 02:00
Location: Durban, South Africa

Post by Richard_ »

Very useful for scripts that require root access while you're not there to type the password in. :-)
AlphA
Registered User
Posts: 3213
Joined: 15 Mar 2005, 02:00
Location: JHB
Contact:

Post by AlphA »

Not very good to have scripts hardcoded with root password though ... 8O
Image
Richard_
Registered User
Posts: 2295
Joined: 18 May 2003, 02:00
Location: Durban, South Africa

Post by Richard_ »

Definitely. Don't use this if said PC is on a network or connected to the net without a firewall. :P
Post Reply