Here Document not working with sudo su [closed] - bash

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I was trying to write a setup.sh script that searches and installs the required components while installing an application. If a required component is not found it will prompt to install it. I have used sudo apt-get install for that, and I want to pass the user supplied password to sudo, like this:
read passwd
sudo apt-get install clisp <<EOF
$passwd
$passwd
EOF
But this is not working. The input password is not being passed to sudo. Why is this not happening? Is there any mistake in my usage?

The password is not read from the standard input but from the "current terminal". This is not changeable via redirection. But sudo provides an optione -S which read the password from standard input and not from the terminal.
Edit: A better solution to the whole problem would be to avoid intercepting the password at all. sudo will ask for the password itself if it requires one. using the -A option you can also provide a graphical UI for this question. And since sudo keeps a timestamp for that input it will not ask for the password the next 15 minutes (by default, i.e. configurable). Therefore multiple sudo calls are also not a problem.

Related

How can I automate password entry for a shell script? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am using openvpn.
To execute the vpn I enter in my terminal the following command string: sudo openvpn /etc/openvpn/ca-mon.prod.surfshark.com_udp.ovpn
Then I am required to enter my password.
Openvpn requires sudo or it won't work.
I created a shell script hoping to eliminate the need to type my password.
after searching for solutions I read tha including "NOPASSWD" would solve my issue. However, NOPASSWD isn't recognized, the script stops with an error on NOPASSWD.
I thought maybe NOPASSWD might only work on BASH so I changed the script for BASH. No difference, still errors out on NOPASSWD.
I'm obviously doing something wrong as I keep reading that it should work.
Any suggestions are greatly appreciated.
My script that works but requires my password after execution:
#!/bin/bash
cd /etc/openvpn
sudo openvpn /etc/openvpn/us-dtw.prod.surfshark.com_udp.ovpn
In your /etc/sudoers file, add
yourusername ALL = (root) NOPASSWD: /"The REAL PATH of your openvpn file"
Then try to rerun the script.

linux sshpass not able to execute command remotely [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have remote red-hat 5.4 machine where I am able to execute
sudo lvdisplay
command locally using xyz user but while executing the same command remotely using xyz user through sshpass, I am getting the result as
sudo: lvdisplay: command not found.
The command I am executing is like
sshpass -p 'password' ssh -p 22 -o StrictHostKeyChecking=no
xyz#hostname sudo lvdisplay
.
Please help me out to resolve the issue.
sshpass -p pass ssh -t user#192.168.XXX.XXX 'ls; bash -l'
Try the above command it worked for me. Remember to replace pass and user.

Mac OS X: Delete my User, or "Current User" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I have a MacBook Air (with OS X El Capitan Version 10.11.5) that is shared by other users.
I have admin privileges.
I want to delete my "User", however, I cannot do such within "System Preference > Users & Groups", because I can delete "Other Users" but not myself as "Current User".
How can I delete my "User" without affecting "Other Users"?
I am not sure about my answer but I think you cannot delete user which is logged in. So you should have logged in by another Admin account and remove yours. And If you have not access to other Admin accounts, create another admin user and delete your user when you logged in at new account
open Terminal and type the following commands, or create .sh file and add them there:
echo "YourPassword" | sudo -S rm -R /Users/YourUser
sudo rm /private/var/db/.AppleSetupDone
sudo dscl . -delete /Groups/YourUser
sudo dscl . -delete /Users/YourUser
Where YourUser could be any user you have already logged in, and "Your Password" (with quotes) is the same password you use to log in your mac.

How to open putty using batch and login then execute list of commands on bash [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I have a Sun OS server with oracle configured on it ; with database 11g i want to take backup , now am connecting to terminal using ssh on putty console but , what i need is finding a way to make it possible to connect using batch to ssh to the server then login then login to oracle then take the backup, is that possible and how.
If you really want to use putty to do this you can use the below in your command prompt in Windows(this will open the putty and its terminal and execute the passed argument in you text file):
putty.exe plink -ssh -load profileName -l username -pw password -m commandPath -t
Or
putty.exe -ssh username#ip -pw password -m commandPath
e.g:
putty.exe -ssh rootz#10.10.10.10 -pw rootzpass -m c:\commands\mycommands.txt
Where profileName is the profile saved in putty and the commandPath is your local directory text file containing the commands you want to execute and the username is the server user and ip is the IP address for the server , the password is your server password then you can put whatever commands you want in your textFile.
Reference
the.earth putty documentation

Transfering postgreSQL DB from one server to another [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am using this command to attempt to transfer a DB
pg_dump -C -h localhost -U OLD_SERVER_USER_NAME site_db | psql -h NEW_SERVER_IP -U postgres site_db
It asks me for a password, which I give and then nothing happens, it just hangs.
What am I doing wrong?
First, to avoid the password prompt, you can set the environment variable PGPASSWORD.
In terms of it hanging, it's quite possible that the piping is "eating" an error that you would otherwise see.
Try breaking it up into separate commands, something like:
pg_dump -C -h localhost -U OLD_SERVER_USER_NAME site_db > db.dmp.sql && psql -h NEW_SERVER_IP -U postgres -f db.dmp.sql site_db
And see if you get any errors from either command.

Resources