I wrote a bash script to get pulled automatically from master repository After it run that means auto enter the username and password. But it's not working. After executing fist command it again asked for a username.
my script is like this
#!/usr/bin/expect
git pull origin master
expect "Username for 'http://192.168.2.xx:xxx':"
send "myUsername\r"
expect "Password for 'http://192.168.2.xx:xxx':"
send "myPassword\r"
interact
Please help me out. Where I am mistaken
Related
i'm trying to write a bash script that will automate some of the operation that we are doing on daily basic:
1. clone different repos
2. checkout some specific commits
3. compile
4. etc.
my challenge is, that I want this script to be used by different users and I don't want the script to prompt for password for each git cmd.
I thought to get the username + pwd as arguments to the script and then
git clone https://username:pasword#gitlab.../repoName/usename/proj.git
but I always get an error of "TCP connection reset by peer".
obviously running ssh command or https command without the username builtin working for me fine
any idea?
If you must use "https" instead "ssh" try with expect script.
#!/usr/bin/expect -f
spawn git pull
expect "Username"
send "put here your username\r"
expect "Password"
send "put here your password\r"
interact
You can use bash and expect in the same script as well.
When I do
git push
I get the command prompt like
Username for 'https://github.com':
then I enter my username manually like
Username for 'https://github.com': myusername
and then I hit Enter and I get prompt for my password
Password for 'https://myusername#github.com':
I want the username to be written automatically instead of manually having to type it all the time.
i tried expect but could not use it
can anyone help me to write a shell script for it?plz:)
Well here is a very small script that would do what you want
#!/bin/expect
spawn git push origin master
expect "Username for 'https://github.com': "
send "MY_NAME_IN_GITHUB"
interact
This way you just have to type your password. You can bind this script to some git command and it can take in extra parameters so that it changes your branches.
But I would advise you to create yourself ssh keys and use them. Here is a great tutorial how to do that :) ssh_tutorial and connect GH to ssh
I have multiple repositories , which I want to convert to git from svn.
I try to write a simple expect script that convert one repo.
#!/usr/bin/expect
spawn svn2git svn://svn-server/repo --username $username --verbose
expect {Password for '$username'}
send "$password\r"
He puts password but then exit by timeout.
Git launches SSH internally to connect to a remote repository, and SSH detects when it is launched from another program, and disallows to enter passwords from scripts as a security feature.
You will need a specialized program like sshpass to enter passwords into SSH from scripts, or set up SSH keys.
I presume svn2git takes more than a few seconds to complete. Add this after your send command
set timeout -1
expect eof
I am working on making a website for a class that you log into with a username and password, and then it takes you to a page that shows your grades in the class.
The website is being run with a bash script, and will be hosted on a machine where the users already have a username and password to login.
I also have a script called calcgrade.sh that will calculate the grades for either the user who is currently logged in, or the user passed to the script as an argument.
So originally, I was going to use this command:
echo -e "$password\n" | sudo -Sk -u $user ./website/calcgrade.sh
to run calcgrade.sh as the user of the website. However, I found out that sudo asks for the password of the user who is currently logged in, not the target user you are trying to run a command as.
So after some reading, I found a better option would be to use su with an expect script, but I can't get it to work. Here is the code for the expect script (currently username and password are hard coded in for testing):
#!/usr/bin/expect
log_user 0
spawn /bin/su myusername
expect "Password: "
send "mypassword"
spawn "./website/calcgrade.sh"
interact
When I run this script, it doesn't seem to log in the user with su, as it goes on to run calcgrade.sh with my account, rather than the user's.
Do you see what is wrong with my script? Or can you see a better way to do what I want?
Also, another problem with this method is that calcgrade.sh is supposed to send some output to stderr, but when I run it with the expect script, the error messages get sent to the website (the server works by sending the html for the website to stdout). Is there a way around this, or might it be better to have the expect script just check with su if username/password is correct, and then if so, then run ./calcgrade.sh $user afterwards?
First of all, here's the correct way to do what you want to do:
Give your web server user sudo permissions to run ./website/calcgrade.sh as any user, without requiring a password.
Have the web server authenticate the user however you see fit.
Have it run sudo -u someuser ./website/calcgrade.sh, no password required.
Now let's look at why your approach didn't work:
It's commonly believed that su switches user. This is not the case. It actually starts a new shell running as another user.
This means that you can't spawn su otheruser, let it finish, and then afterwards spawn calcgrade.sh.
Instead you have to run su otheruser, and then send commands to the shell that su starts:
#!/usr/bin/expect
log_user 0
spawn /bin/su someuser
expect "Password: "
send "somepassword\n"
# Now wait for a prompt and send the command to run
expect "$"
send "./website/calcgrade.sh\n"
interact
I want have a patch run every Monday to get the latest Android source code and have it built. It seems everything goes well except I have to help 'repo' to confirm my username and email when I get the patch run. The patch will be scheduled in midnight so I guess I have no chance to offer my help to confirm it... How could I configure repo to dismiss the step? Otherwise, is there any way to input 'enter' by bash script once the script gets prompt?
repo simply builds on top of git.
To set your name in git,
git config --global user.name "Your Name"
git config --global user.email you#example.com
I solved this problem by 'expect', here is the script looks like
expect - << EOF
exec repo init -u ssh://${USER}#<your_repo_server>/<your_manifest.git>
exepect “Your name \[Your Name\]:"
send "\r"
expect "Your Email" \[Your#email.com\]:"
send “\r"
expect "is this correct \[y/n\]?"
send "y\r"
EOF