LinuxQuestions.org
Visit Jeremy's Blog.
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-21-2012, 02:24 PM   #1
PoleStar
Member
 
Registered: Jul 2010
Posts: 231

Rep: Reputation: 2
running shell command locally and over ssh


Hello,

I ran following command on the server and it brought back required information.


Code:
> cut -d: -f1 /etc/passwd | while read xxx ; do  last $xxx | head -n 1   ; done;
Code:
root     pts/0        XX.XXX.2.173     Tue Oct 18 10:30 - 11:22  (00:51)


But when we run same command over ssh it doesn't bring the same results.
It seems like over ssh $xxx could not hold information.
Below seems like it run
Code:
last
command with out any variable in $xxx.




Code:
ssh user@localhost " cut -d: -f1 /etc/passwd | while read xxx ; do  last $xxx | head -n 1   ; done;"
user@localhost's password: 
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
user pts/0        XX.XXX.XXX.123    Sat Jul 21 14:10   still logged in   
[user@linux ~]$

Last edited by PoleStar; 07-21-2012 at 03:22 PM.
 
Old 07-21-2012, 07:41 PM   #2
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
Hello,

That is because the expanson of $xxx happens in the shell of your local machine before issuing the ssh command.
Simply replace the double quotes by simple quotes ' and it will work ;-)

Regards,
Antegallya

Last edited by antegallya; 07-21-2012 at 07:42 PM. Reason: typo
 
Old 07-22-2012, 01:22 PM   #3
PoleStar
Member
 
Registered: Jul 2010
Posts: 231

Original Poster
Rep: Reputation: 2
Code:
\$xxx
worked.
Thanks for the idea.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Need user account which can connect by ssh but not login locally nor run shell taylorkh Linux - General 11 07-05-2011 08:49 AM
Disconnect from SSH with command running - Shell script striker Programming 13 08-24-2009 09:18 PM
Running X + App Locally via a Remote Shell cronicded Linux - Desktop 3 12-21-2007 11:56 PM
running shell command on remote machine with ssh qrshat Solaris / OpenSolaris 3 08-17-2006 08:32 AM
Running a shell script remotely via 'ssh <hostname> <command>' davee Linux - General 4 10-09-2005 02:38 AM

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

All times are GMT -5. The time now is 05:37 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