LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to Enable Alias Command on Remote Machine Using SSH (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-enable-alias-command-on-remote-machine-using-ssh-653602/)

bichonfrise74 07-04-2008 12:40 PM

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?

Count Zero 07-04-2008 12:55 PM

Quote:

Originally Posted by bichonfrise74 (Post 3204143)
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?

bichonfrise74 07-04-2008 05:02 PM

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?

i92guboj 07-04-2008 08:11 PM

Quote:

Originally Posted by bichonfrise74 (Post 3204353)
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.

bichonfrise74 07-04-2008 11:18 PM

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?

i92guboj 07-04-2008 11:52 PM

Quote:

Originally Posted by bichonfrise74 (Post 3204572)
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.

bichonfrise74 07-05-2008 09:28 PM

Hi i92guboj,

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

i92guboj 07-07-2008 06:14 AM

Quote:

Originally Posted by bichonfrise74 (Post 3205223)
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.


All times are GMT -5. The time now is 02:48 AM.