Bash - Curl (6) couldn't resolve host issue - bash

I am having a problem with my bash script. It is producing an error of
curl (6) couldn't resolve host
What have I done wrong?
The following is my bash script.
#!/bin/bash
string="$(mysql -u root -p Company 'select name from HR')"
url="http://www.company.com/company/hr/$string"
curl -F $url

According to the man curl, error 6 means "Couldn't resolve host. The given
remote host was not resolved." so you will have to check if the hostname of the
url is resolvable to an ip address.
when you need to submit data to a server, for example with the form below,
<form method="POST" enctype='multipart/form-data' action="upload.cgi">
<input type=file name=upload>
<input type=submit name=press value="OK">
</form>
you can do it curl with the following equivalent. (make sure the server that
you submitted is ready to receive the data too)
curl -F upload=#localfilename -F press=OK [resolv-able url]

Try printing out the whole string/url. I believe it should have some problems in it.

And can you ping "www.company.com" (I'm assuming that's not the real name you're connecting to) at all?
And it might be worthwhile printing out the $url variable before you curl it since it may be malformed.
And one final thing. Are you sure you should be using -F? This appears to be automated form filling. Is it possible you wanted to "fail silently" option -f?

Just for completeness: this happens also if there are problems on your network.
For instance, to test this, on your local machine shutdown the connection to the internet and try to connect to the URL: the exact same error is returned.
So currently I have no idea of how to distinguish problems on the remote server from problems on our own network.

This could be a DHCP problem. I was seeing the same and similar error messages trying to update and install NPM packages and run Curl commands in my Window WSL2 Ubuntu terminal. After updating the DNS by running sudo echo nameserver 8.8.8.8 > /etc/resolv.conf I was able to install and update packages again. I spent days trying to troubleshoot this and never thought to check for DNS issues.

Related

How to find simple ip address of local server

This may be something very simple and obvious but I’m learning the command line. I’m trying to identify the IP address I need to load in a web browser to access my local server - for example, after entering these simple steps in the command line to create a folder with an index file:
mkdir www
nano index.html
Then running the server:
sudo python -m SimpleHTTPServer &
Displays this message: [1] 41749
What IP address do I need to load in a web browser to see the test index.html file? I’ve tried:
http://127.0.0.1/
http://localhost/
Also, entering hostname -i returns this message:
hostname: illegal option -- i
usage: hostname [-fs] [name-of-host]
Can anyone explain what’s going on here? Probably something very obvious. Also it feels that other commands aren’t working as usual as the ip addr command now returns -bash: ip: command not found.
Thanks for any help here.

wget unable to establish SSL connection in bash script

The following command works on the command line:
wget --secure-protocol=PFS -O dcm4chee-arc-5.15.1-mysql.zip https://sourceforge.net/projects/dcm4che/files/dcm4chee-arc-light5/5.15.1/dcm4chee-arc-5.15.1-mysql.zip/download
However, when I put the exact same line into a bash script (it's inside a function), it results in this error:
Resolving sourceforge.net (sourceforge.net)... 216.105.38.13
Connecting to sourceforge.net (sourceforge.net)|216.105.38.13|:443... connected.
Unable to establish SSL connection.
I've even pulled it out of the function to see if that makes any difference, but it doesn't.
Any thoughts?
Kicking myself ... my IDE had #!/usr/bin/env bash at the top of the file, whereas changing it to simply #!/bin/bash made everything work as expected. I thank you all for the responses, crediting #Mihai with direct assistance due to the comment about "environment"

How to copy files from one machine to another machine

I want to copy /home/cmind012/m.sh from one system to another system (both system Linux) using shell script.
Command $
scp /home/cmind012/m.sh cmind013:/home/cmind013/tanu
getting message
ssh: cmind013: Name or service not known
lost connection
It seems that cmind013 is not being resolved, I would try using first
nslookup cming013
and see what why donesn't it resolve.
It seems that you are missing the IP Address/Domain of the remote host. The format should be user#host:[directory]
You could do the following:
scp -r [directory/files] [remote host]:[destination directory]
ex: scp -r /var/www/html/* root#192.168.1.0:/var/www/html/
Try the following command:
scp /home/cmind012/m.sh denil#172.22.192.105:/home/denil/

X11 connection rejected because of wrong authentication

I am getting a error while accessing the firefox using X11Forwarding.
[root#station2 ~]# firefox
KiTTY X11 proxy: wrong authorisation protocol attemptedKiTTY X11 proxy: wrong authorisation protocol attemptedError: cannot open display: localhost:10.0
setup the following values: /etc/ssh/sshd_config
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
** Installed the package**
#yum install xorg-x11-xauth
#yum -y install xauth
[root#station2 .ssh]# echo $DISPLAY
localhost:10.0
#mkxauth -c
adding key for station2.example.com to /root/.Xauthority ... done
export XAUTHORITY=$HOME/.Xauthority
This fix worked for me
There is a hard, if not even impossible, to find (by search engine) scenario that may may cause that error message.
Preliminary note: The topic of this answer is not to discuss if it is a safety
risc or recommondable at all to use a graphical desktop as root on an remote, display-less, webserver.
Scenario:
A remote internet connected Linux server S has assigned the domain
name example.com to it's public IP4-address 192.0.2.1.
The /etc/hostname file on S contains the single line example.
The /etc/hosts
file on S contains the line 127.0.0.1 localhost example.com example.
The (remote) ssh access to S is by (sshd-) configuration (on S) forbidden
for root by the line DenyUsers root in /etc/ssh/sshd_config, but
allowed for a dummy user user1. From a client computer C a ssh
connection, using the ssh parameter -X or -Y, is established to S
as user user1.
Then, in a remote terminal on S owned by user1,
if any X11 related command is tried to be executed as root, may it be by
su, then trying to start the X11 desktop environment
or, as in the concrete case executing a script containing
#!/bin/bash
su --preserve-environment -c "xfce4-session &" root
the error message
X11 connection rejected because of wrong authentication.
is output and the start of any X11 related program fails.
The DISPLAY variable of root's environment contains
example.com:10.0
then.
One solution to the problem is, in this special case, to modify the line
127.0.0.1 localhost example.com example
in /etc/hosts to
127.0.0.1 localhost
Solution: run the application with the same user you are SSHing.
I have also encounter such errors while using X11.
The source of my problem was that i used SSH with my own username (which was not root).
Then, once logged in i tired running stuff with X11 while doing "su" or doing "sudo",
the problem with that is that the SSH session is configured with your own username - e.g: Raj, but then you switch to user root which is not part of the X11 session.
So what you should do is simply try to run the application (firefox in your case) with the same user you started the X11 session.
Hope this helps.
Talel.
I ran into this running gvim over ssh -t -Y and the solution that worked for me was:
xauth add $(xauth -f ~<logon_user>/.Xauthority list | tail -1) ; export NO_AT_BRIDGE=1 # gvim X11 fix for remote GUI failure after su
I do not know where I stumbled on this answer so I cannot give credit to the author.

How would I construct a terminal command to download a folder with wget from a Media Temple (gs) server?

I'm trying to download a folder using wget on the Terminal (I'm usin a Mac if that matters) because my ftp client sucks and keeps timing out. It doesn't stay connected for long. So I was wondering if I could use wget to connect via ftp protocol to the server to download the directory in question. I have searched around in the internet for this and have attempted to write the command but it keeps failing. So assuming the following:
ftp username is: serveradmin#mydomain.ca
ftp host is: ftp.s12345.gridserver.com
ftp password is: somepassword
I have tried to write the command in the following ways:
wget -r ftp://serveradmin#mydomain.ca:somepassword#s12345.gridserver.com/path/to/desired/folder/
wget -r ftp://serveradmin:somepassword#s12345.gridserver.com/path/to/desired/folder/
When I try the first way I get this error:
Bad port number.
When I try the second way I get a little further but I get this error:
Resolving s12345.gridserver.com... 71.46.226.79
Connecting to s12345.gridserver.com|71.46.226.79|:21... connected.
Logging in as serveradmin ...
Login incorrect.
What could I be doing wrong?
Use scp on the Mac instead, it will probably work much nicer.
scp -r user#mediatemplehost.net:/folder/path /local/path

Resources