LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-08-2009, 05:26 AM   #1
openSauce
Member
 
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Rep: Reputation: 39
Can't use aliases in non-interactive ssh command


Hi,

when I use ssh to open an interactive shell on my machine, I can use all the aliases I normally would on that machine. But when I use ssh to run a single non-interactive command, the aliases don't work. How can I fix this?

Example:
Code:
# sshhome is an alias to ssh to my home machine
3$ sshhome
Last login: Thu Jan  8 11:01:44 2009 from *****
~$ alias testal
alias testal='echo aliases are A-OK'
~$ testal
aliases are A-OK
~$ exit
logout
Connection to ***** closed.
3$ sshhome "alias testal; testal"
alias testal='echo aliases are A-OK'
bash: testal: command not found
3$
Note that using the alias command does correctly display the alias.

Last edited by openSauce; 01-08-2009 at 05:27 AM. Reason: Typo
 
Old 01-08-2009, 06:11 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by openSauce View Post
Note that using the alias command does correctly display the alias.
Yes. The alias is assigned but it is not expanded (executed) when the shell is not interactive.

You have two options:
1) convert the aliases in functions
2) add the following line to your .bashrc on the remote machine
Code:
shopt -s expand_aliases
 
Old 01-08-2009, 06:52 AM   #3
openSauce
Member
 
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Original Poster
Rep: Reputation: 39
Option 2 isn't working for me unfortunately. Also doesn't work if I do the shopt as part of the ssh command: ssh "shopt -s expand_aliases; [command]". Option 1 works fine, although feels kludgy. Thanks
 
  


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
How do you turn off login banner for non-interactive ssh? cpatter12 Linux - Security 21 12-14-2016 02:35 PM
LXer: sshpass - Non-interactive ssh password authentication LXer Syndicated Linux News 0 05-04-2008 04:50 PM
mail command non-interactive snowman81 Programming 4 03-13-2008 10:44 PM
How to get a non-interactive ssh connection jahvascriptmaniac Linux - Networking 7 11-18-2007 03:19 AM
non-interactive ssh podollb Linux - Software 3 04-20-2004 03:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:29 AM.

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