How to pass the password to su/sudo/ssh without overriding the TTY?
For sudo there is a -S option for accepting the password from standard input. Here is the man entry:
-S The -S (stdin) option causes sudo to read the password from
the standard input instead of the terminal device.
This will allow you to run a command like:
echo myPassword | sudo -S ls /tmp
As for ssh, I have made many attempts to automate/script it's usage with no success. There doesn't seem to be any build-in way to pass the password into the command without prompting. As others have mentioned, the "expect" utility seems like it is aimed at addressing this dilemma but ultimately, setting up the correct private-key authorization is the correct way to go when attempting to automate this.
Ant sshexec task unable to execute remote script file separate from session
Never mind, I found it. Still need to combine nohup
and background running with the startup script. Plus the "dirty workaround" from here
https://unix.stackexchange.com/questions/91065/nohup-sudo-does-not-prompt-for-passwd-and-does-nothing (was actually brilliant)
End result:
echo password | sudo -S env && sudo sh -c 'nohup startup.sh > /dev/null 2>&1 &'
Ant exec task as another user
You could use the sshsexec task. Connect locally or to a remote machine:
<sshexec host="localhost"
username="dude"
password="yo"
command="touch somefile"/>
This task will require the optional jsch.jar to be installed in your ANT lib.
Specifying a pirvate key would enable a password-less login.
Related Topics
How to Join Multiple Txt Files into Based on Column
How to Avoid Sigchld Error in Bash Script That Uses Gnu Parallel
How to Check That Smart Card Is Working on Linux
Find Ip Address of My System for a Particular Interface with Shell Script (Bash)
Assembly Divisions and Floating Points
How Limit Memory Usage for a Single Linux Process and Not Kill The Process
Oracle Query - Ora-01652: Unable to Extend Temp Segment But Only in Some Versions of Sql*Plus
Find String and Replace Line in Linux
Get The Name of The Directory Where a Script Is Executed
How to Customize or Remove Extra Linux Kernel Version Details Shown at Boot
Why Does High-Memory Not Exist for 64-Bit Cpu
Numa-Aware Named Shared Memory for Linux
Cannot Get Qwindow::Fromwinid to Work Properly
How to Use Sed to Replace a String in a File with a Shell Variable
Bash Exit Script from Inside a Function
Is It Correct to Use The Rc.Local File to Start a Program When The System Starts