LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 03-01-2013, 05:54 AM   #1
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Rep: Reputation: Disabled
rsh command issue


Hi Guys,
iam not able to run below rsh command having the for loop having back tips in it
please suggest i wasted whole one day to figure it out
but still no solution.
please assits what is the issue
+++++++++++++++++++++++++++++++
rsh -l <user name> <machine name> "for i in `cat ~/file`
do
echo $i
done"
+++++++++++++++++++++++++++++++
i am using redhat linux 5
 
Old 03-01-2013, 06:25 AM   #2
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 50
What do you want to do using this script.
I think this for loop will show every word before space as a separate line.
Have you run this for loop on your system first? Is it giving proper results?
If you want to run on other machine, you can use ssh too.

I can give you example to run the script using ssh.
You have used double quote that can be the problem.
An example to run the script containing loop
Code:
#!/bin/bash
ssh 192.165.xx.xx 'for i in `cat /path/of /the/file` ; do echo $i; done'
My public key is saved as 'authorized_keys' in .ssh of server that's it does not ask me password while running the script.

Where are you getting the problem?
Is it just finished showing command prompt of remote machine and not executing the rest of the script?
Paste your error, if there is any.

Last edited by fortran; 03-01-2013 at 06:56 AM.
 
1 members found this post helpful.
Old 03-01-2013, 07:14 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Perhaps you should get any error or message while running it? Can you make a try on:
Code:
~$ rsh -l <user name> <machine name> "for i in `cat ~/file`; do echo $i; done"
Also make a try with what @pavi_kanetkar has said above.
 
Old 03-01-2013, 09:56 AM   #4
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
we're using rsh in our project & the actual issue is we're not able to use back tick in a rsh command..

any thoughts how we can use back ticks in rsh commands
 
Old 03-01-2013, 10:18 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
@vicky007aggrwal:
In that case, if login shell for user username on machinename is bash, then you can:
Code:
~$ rsh -l <username> <machinename> "for i in $(cat ~/file); do echo $i; done"
But how can you say that rsh won't accept backticks? Also, as asked above, did you get any error or message(s)?
 
Old 03-01-2013, 01:39 PM   #6
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
Thanks shiva & how to use pwd command in rsh as below also
Not working. Please suggest

rsh -l <user name> <machine name> "cd /home/hgs/her/server;ps -ef | grep 'pwd' `

In this also pwd command is showing current directory of my base/source
Machine not destination machine.

Kindly help , m bit naive in these

Last edited by vicky007aggrwal; 03-01-2013 at 01:41 PM.
 
Old 03-01-2013, 01:49 PM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Give a try to:
Code:
~$ rsh -l <user name> <machine name> "cd /home/hgs/her/server; pwd"
Do not use ps -ef | grep 'pwd', it shouldn't give you appropriate results.
 
Old 03-01-2013, 01:52 PM   #8
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
Thanks shivaa for so prompt reply,but my objective is
To grep the process running from the respective directories
Do you hve any better solution

Can u help me in understand why ps -ef|'pwd' is not apt one
 
Old 03-01-2013, 02:00 PM   #9
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Sorry, I thought that you just need to check working directory.

You can try:
Code:
~$ rsh -l <username> <machinename> "cd /home/hgs/her/server; ps -aef | grep $(echo $PWD)"
Code:
~$ ps -ef  |grep 'pwd'
It will return all process with name having 'pwd' inside it, which don't make much sense. Instead you can:

Code:
~$ ps -aef | grep $(echo $PWD)
But let know know why you want to get a process containg PWD word or working directory?

Last edited by shivaa; 03-01-2013 at 02:02 PM. Reason: Formatting
 
Old 03-01-2013, 02:01 PM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 2,129

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
Do the pwd without the ps... the string you get back will be something like '/home/username'.

The ps -ef command will give you strings like "gdm 6765 1 0 Feb27 ? 00:00:00 /usr/libexec/at-spi-bus-launcher" or "username 30558 1 0 08:59 ? 00:00:02 nautilus -n"

Command executed do not necessarily have "/home/username" format... usually they are relative paths, not full paths (as shown in the second line - the command is nautilus... but unless the user types in the full path /usr/bin/nautilus to start the program, the "/usr/bin" will not be present, and neither will the "/home/username/xxx" show for the "xxx" program - only "xxx" will be there.

BTW, the reason your `pwd` only executes locally because your string is being interpreted locally before being passed to the remote system. If you want to pass the `pwd` to the remote system, enclose the command string with single quotes (apostrophe) instead of double quotes.

Last edited by jpollard; 03-01-2013 at 02:06 PM.
 
1 members found this post helpful.
Old 03-01-2013, 03:23 PM   #11
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,937

Rep: Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602
i think we volleyed back and forth enough here. can the op explain why the antiquated and insecure program rsh is preferable to ssh ?

also how are you sure that the backticks is what is messing up your script.

you will probably get better results if you paste a sample of the inputs and what you want the output to look like.
 
Old 03-01-2013, 11:44 PM   #12
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
thanks everyone for your help, jpollard your suggestion worked when i used the single quotes with back ticks in my rsh command

i have one last issue now, let me explain my scenario to clear out the confusion , i am invoking below command

+++++++++++++++++++++++++++++++++++++
DIR_LOCATION=$1
rsh -l <username> <machinename> 'cd $DIR_LOCATION; ps -aef | grep `pwd` | grep -v grep| grep -i catalina;echo $?'
+++++++++++++++++++++++++++++++++++++
now what is happening is that $DIR_LOCATION variable is not getting replaced with its value as i am using single quotes but the irony the back tick only works in single
quotes. I tried using doube quotes in place of single but then the command in back tick is not getting executed.

we have one legacy application which is been configured with rsh oonly not ssh,thats why i have to go with that only

Please please share your thoughts & help me in resolving this issue
thanks again for your time.
 
Old 03-01-2013, 11:57 PM   #13
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
This is because you've declared this variable in on your local machine, but trying to use it on remote machine. DIR_LOCATION is not any shell or environmental variable, so your system cannot take it's value until it's declared in the remote system.

Just do like:
Code:
~$ rsh -l <username> <machinename> 'DIR_LOCATION=$1; cd $DIR_LOCATION; ps -aef | grep `pwd` | grep -v grep| grep -i catalina;echo $?'
 
1 members found this post helpful.
Old 03-02-2013, 12:09 AM   #14
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
Thanks SIva, there is bit more to my use case,actually i canont use $1 directly as i have series of other variables invloved in this process.

As mentioned below APP_STRING & DIR_LOCATION are GLOBAL variables, i cannot afford to write the same variable assignments again in rsh

is there any other approach that i can use, sorry for not narrating the complete scenario earlier but now its complete.

$APP_STRING=`cat configfile | grep -i $1`
$DIR_LOCATION=`echo $APP_STRING |awk -F'|' '{ print $2 }'
rsh -l <username> <machinename> 'cd $DIR_LOCATION; ps -aef | grep `pwd` | grep -v grep| grep -i catalina;echo $?'
 
Old 03-02-2013, 01:05 AM   #15
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Well, in that case, better to create a script on remote machine, add all stuff in that script and invoke that script from your local machine using rsh.

On remote machine:
Code:
~$ vi /home/username/myscript.sh
#!/bin/bash
APP_STRING=`cat configfile | grep -i $1`
DIR_LOCATION=`echo $APP_STRING |awk -F'|' '{ print $2 }'`
cd $DIR_LOCATION
ps -aef | grep `pwd` | grep -v grep| grep -i catalina
echo $?
Then on local machine:
Code:
~$ rsh -l <username> <machinename> "./myscript.sh"
OR
~$ rsh -l <username> <machinename> "bash myscript.sh"
OR
~$ rsh -l <username> <machinename> "./myscript.sh <something>"

Note: <something> will be used as $1 i.e. argument passed to the script.
Also take a note, do not use $ symbol before variable name while declaring it. But use when invoking it.

Last edited by shivaa; 03-02-2013 at 09:56 AM. Reason: Typo
 
  


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
Simple rsh issue Stevie-B-242 Linux - Enterprise 12 09-24-2010 10:15 AM
rsh command rehan999 Linux - Software 5 03-25-2008 04:04 PM
permission denied using rsh (security not an issue) Singist Linux - Networking 1 04-04-2006 02:22 PM
rsh issue in AIX boxes oosii AIX 2 07-21-2005 07:34 AM
weird issue with RSH over a network, anyone seen this? govtlinux Red Hat 0 11-12-2004 09:39 AM


All times are GMT -5. The time now is 10:17 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration