LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-04-2008, 12:40 PM   #1
bichonfrise74
LQ Newbie
 
Registered: Jul 2008
Posts: 24

Rep: Reputation: 15
How to Enable Alias Command on Remote Machine Using SSH


Hi,

I basically want to run my alias commands on a remote machine via SSH. So, if I do this, ssh test_machine "find_me" (where find_me is an alias command), it will give me this error.

ksh: find_me: not found

How do I solve this?
 
Old 07-04-2008, 12:55 PM   #2
Count Zero
Member
 
Registered: Feb 2008
Distribution: Debian wheezy
Posts: 130

Rep: Reputation: 15
Quote:
Originally Posted by bichonfrise74 View Post
Hi,

I basically want to run my alias commands on a remote machine via SSH. So, if I do this, ssh test_machine "find_me" (where find_me is an alias command), it will give me this error.

ksh: find_me: not found

How do I solve this?
uhm, maybe a stupid question but just to make sure, have you aliased the commands on the remote machine? Just because you have them set as alies on the machine you're logging in from doesn't mean you have the alias set on the remote machine, since you log in to the remote, i.e. start a new session there. Or have I misunderstood you?
 
Old 07-04-2008, 05:02 PM   #3
bichonfrise74
LQ Newbie
 
Registered: Jul 2008
Posts: 24

Original Poster
Rep: Reputation: 15
Hi Count Zero,

Yes, the command has been alias on the remote machine. So, if I log to the remote machine and I ran "find_me", then it will perform the command.

What I want is to run the command: ssh test_machine find_me, and it will run the command without me needing to log to the machine anymore. This is like if I type ssh test_machine ls, it will list the files but this isn't a problem because ls is not an alias command.

Does it make sense?
 
Old 07-04-2008, 08:11 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by bichonfrise74 View Post
Hi Count Zero,

Yes, the command has been alias on the remote machine. So, if I log to the remote machine and I ran "find_me", then it will perform the command.
Note that the rc files read are usually not the same if you use a login shell instead of a non-login one.

For example, bash reads ~/.bashrc when opened as an interactive non-login shell, but it reads ~/bash_profile instead if it's ran as a login shell. Read "man bash" for complete info.

I don't know anything about ksh, but "man ksh" or "info ksh" probably have some tips on this.

Alternatively, you can try to rewrite them as functions or scripts if that doesn't hepl.
 
Old 07-04-2008, 11:18 PM   #5
bichonfrise74
LQ Newbie
 
Registered: Jul 2008
Posts: 24

Original Poster
Rep: Reputation: 15
Hi i92guboj,

So, if the remote machine uses bash. And I put the alias command in .bashrc, then theoretically it should work (ssh to the remote machine and run an alias command), right? Is this what you mean?
 
Old 07-04-2008, 11:52 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by bichonfrise74 View Post
Hi i92guboj,

So, if the remote machine uses bash. And I put the alias command in .bashrc, then theoretically it should work (ssh to the remote machine and run an alias command), right? Is this what you mean?
Yes, bashrc will be read. But as I said, I am not sure that aliases will work because of their nature. Functions should, though. So, at it worst, you might need to rewrite the alias as a function, which is trivial enough.
 
Old 07-05-2008, 09:28 PM   #7
bichonfrise74
LQ Newbie
 
Registered: Jul 2008
Posts: 24

Original Poster
Rep: Reputation: 15
Hi i92guboj,

Can you give an example of rewriting the alias as a function? Thanks.
 
Old 07-07-2008, 06:14 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by bichonfrise74 View Post
Hi i92guboj,

Can you give an example of rewriting the alias as a function? Thanks.
Yep.

For example, if you have this alias:

Code:
alias ll='ls -l'
You could write this function instead:

Code:
function ll () {
 ls -l $@
}
The $@ passes all the arguments after ll to the ls -l command. Note that functions do not work by direct substitution, like aliases or variables.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't SSH to remote machine: Connection closed by remote host Avatar Linux - Networking 35 10-23-2017 12:21 AM
SSH connection to remote machine... harishkrishnan Linux - Networking 5 11-10-2007 12:35 AM
running shell command on remote machine with ssh qrshat Solaris / OpenSolaris 3 08-17-2006 07:32 AM
how to open a dilog on local machine when i do ssh to remote machine fahad26 Programming 3 05-03-2005 07:39 PM
ssh not connecting to a remote machine. Eux Debian 5 09-22-2004 04:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration