Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Try putting single quote around the command you want ssh to execute @b and also put brackets around your variables to ensure it sees them distinctly:
ssh ${a}@${b} 'mkdir abc'
Also if that still doesn't work be sure to verify a simple ssh works as you expect:
ssh <user>@<hostIP>
It's always possible your issue has nothing to do with variables but simply a failure to connect to the remote server as the user you're specifying which is what the error is telling you. Command line without variables would give same error if that is the case.
thanks... Yeah I have tried using the basic ssh <user>@<ip> command and it works perfectly.. will try the ssh ${a}@${b} 'mkdir abc' command and let u know abt the result..
What shell are you using?
In bash, neither the braces (since variable names cannot contain '@') nor the single quotes are necessary, although the quotes are recommended and the braces make the command more readable. The command you showed in the original post just has to work the way it is. Please check the contents of the variables a and b and make sure you didn't misspell any of them.
manually, all commands are working perfectly.
automatically, all commands are working except last command.
its not accepting '$' (maually & automatically)
giving an error: ssh: connect to host port 22: Connection refused
please use [code]here comes your script[/code] to keep formatting
also try
Code:
#!/bin/bash
set -xv
.....
to see what's happening. (That will not solve anything, just print the lines as they executed, so you will be able to check tthc program flow).
Also at the last line you do not need echo:
Code:
ssh $a@$b 'mkdir -p ~/.ssh'
can you please explain what do you mean by "its not accepting '$' (maually & automatically)"
in the above.. a, b ,c is a variable in which values of username, password, IP address stored from the file (rs).
checked these three commands one by one maually.. its working
if i write: ssh $a@$b 'mkdir -p ~/.ssh' instead of ssh root@XXX.XXX.XXX.XXX 'mkdir -p ~/.ssh'
then it is not taking value of a and b
in the above.. a, b ,c is a variable in which values of username, password, IP address stored from the file (rs).
checked these three commands one by one maually.. its working
if i write: ssh $a@$b 'mkdir -p ~/.ssh' instead of ssh root@XXX.XXX.XXX.XXX 'mkdir -p ~/.ssh'
then it is not taking value of a and b
Yeah - but if "b" is supposed to be the password it definitely won't work.
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,920
Rep:
Just as an aside
Code:
echo -ne "\n"
Is meaninless, the -n switch tells echo to suppress the trailing newline and the -e switch tells it to accept escape codes, so you are saying efectivly don't use new line and add new line, the above command is just the same an echo with no arguments.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.