I have a need to perform a runas command, and send an enter keypress to the command without user interaction.
I understand that piping results out to a file, but i want to do it the other way, send n enter keypress to the command.
This is the command
runas.exe /user:XXX\USER_LOGIN notepad.exe
When this command is run, it prompts for a password... i dont want to supply a password, just press the enter key.
FYI - this is a very simple user refresh, so it doesn't go stale when not used in a while.
Try piping in a blank quoted string:
echo "" | runas.exe /user:XXX\USER_LOGIN notepad.exe
Related
I have a program that interactively logins a user. I used the heredoc to automate the process.
./login <<EOF
user1#test.com
password
EOF
I was expecting the output would be something like this. This is what it displays when I run the program without the heredoc and type in username and password myself.
$ ./login
Enter your email: user1#test.com
Enter your password: password
Successfully logged in.
However, I only see this.
$ ./login
Enter your email:
Enter your password:
Successfully logged in.
As you can see, all of the heredoc inputs are not printed out, even though the program seems to be getting the stdin correctly. What's the reason for this? It would be great if I could still see those inputs to help me debug problems. Thanks.
The login program disables the local echo (see https://man7.org/linux/man-pages/man1/stty.1.html).
Update
If the login program is writen by you, then is much easier, just echo the values after reading them
ECHO is a feature of the tty when users manually type chars to the tty. Your ./login << ... does not get input from the tty so the heredoc is not echoed. It's just like, for example,
grep something < /some/file
where you don't want it to echo the whole file's data.
I am trying to create a bash script to operate another bash script through CRON without the need for human intervention.
The script needs to be able to interact with the other script so that it accomplishes:
Enter
Press a number..
Then takes you to another section of the script where you need to enter another number..
Then enter another number..
Press enter again..
I can't get the script to hit Enter correctly. What I have so far, "echo | ./module1.sh" flickers, even tried "echo "\n"" which doesn't work.
#!/bin/bash
cd /home/usernamehere/scripts
echo | ./module1.sh
echo "1"
This script requires a person to sit at the terminal while it finishes what it needs to or be run in a tmux session with the user safely exiting the session.
If everything is read from stdin (as opposed to from the terminal device--which is what passwd and screen editors do), and the script requires you to enter ENTER, 1, 2 and 3, you can run it with
printf '\n1\n2\n\3\n' | ./module1.sh
An alternative is with a here-document (read your shell's manual page):
./module1.sh << EOF
1
2
3
EOF
I am running simulations in parallel using mpich2. I've got rather stringent security on my workstation, and must register using a new password each time I run a simulation. I have to enter:
mpiexec -register
which then prompt me for a username, and then prompt me for a password. Unfortunately, there seem to be no way to pass the user/pass to mpiexec on a single line, e.g.
mpiexec -register user:pass
does not work.
I'm trying to prepare a batch file that can automatically pass the username and password to the mpiexec prompts, but I cannot seem to get it to work. I've tried various things like timeout /t 5 but that doesn't work.
Can anyone tell me how to pass these inputs to the mpiexec program prompts in a batch file?
Thanks!
EDIT: I think I am getting closer. I've tried
(
echo username
echo password
echo password
) | mpiexec -register
which appears to be passing the username and password inputs to the mpiexec prompts. Program is still hanging at the next step however - not sure if that's a problem with the way I'm passing these or not.
You could redirect or pipe into mpiexec.
With redirection it's gets a bit nasty for user/password entries, as there are often unwanted (and unvisible) spaces at the line ends.
(
echo user
echo pwd
) | more > fetch.txt
Creates in fetch.txt
user<space>
pwd<space>
When you want to suppress the spaces use a file redirection instead
(
echo user
echo pwd
) > file.tmp
< file.tmp mpiexec -register
In both cases (redirection or pipe), you need to serve all inputs for the program, not only username and password.
You can't enter inputs from keyboard anymore.
I have a command which takes 2 arguments.
When I run the command manually, I do this way:
cmd -i xyz.dat
hit enter
enter password in the prompt
hit enter
confirm password
My script needs to do the above operations without expecting user to enter password. I can hardcode the passwords in the file, but need a way to run this command successfully when I execute the shell script.
As on Feb 7th,
I have expect installed on my AIX. When I type expect at the command prompt, the prompt changes to expect 1.1> OS is 64 bit AIX
I have followed the instructions mentioned in the below comment, but I keep getting error - could not execute the command; no such file or directory"? I am able to manually run this command from same directory I am running the script. Besides that I have given the complete path of the command and the
file.
I am pasting another program I tried to su with root password as below: i get the same error message when I run the test program. I doubt if this is something related to quotes.
#!/bin/bash
set timeout 20
spawn "su"
expect "Password:" { send:"temp123\r" }
interact
Can someone please help me fix this error?
Sounds like you want to use expect. Here is a page with some examples.
So for your command you would want something like:
#!/usr/bin/expect
set timeout 20
spawn "cmd -i xyz.dat"
expect "<your password prompt" { send "<your password>\r" }
expect "<your password confirmation prompt" { send "<your password>\r" }
interact
I want to write a simple bash script using ncat to open a connection to a ISP and its port.
The first command would be:
nc address port
Upon doing this, I am prompted first to provide a username. I must hit ENTER, and then I will be prompted to provide a password and then I must hit ENTER again.
After this, I want to open a Terminal process window. Can anyone point me to sufficient resources for this type of scripting?
I know the username and password already, but I'm not too sure how to work around the fact that I must provide it and then hit enter. I'm also unsure how to open a new Terminal proceses.
Thanks in advance!
Check out expect script
Expect
Example:
# Assume $remote_server, $my_user_id, $my_password, and $my_command were read in earlier
# in the script.
# Open a telnet session to a remote server, and wait for a username prompt.
spawn telnet $remote_server
expect "username:"
# Send the username, and then wait for a password prompt.
send "$my_user_id\r"
expect "password:"
# Send the password, and then wait for a shell prompt.
send "$my_password\r"
expect "%"
# Send the prebuilt command, and then wait for another shell prompt.
send "$my_command\r"
expect "%"
# Capture the results of the command into a variable. This can be displayed, or written to disk.
set results $expect_out(buffer)
# Exit the telnet session, and wait for a special end-of-file character.
send "exit\r"
expect eof
The secret lies in the HEREDOC
You can solve this problem with something akin to:
$ command-that-needs-input <<EOF
authenticate here
issue a command
issue another command
EOF
Look at the link I provided for here documents - it includes support for variable substitution and lots of other useful things. Enjoy!