- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- working with $(...) and echo ${...} in combination...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 03:37 AM
02-26-2003 03:37 AM
$ date
Wed Feb 26 12:24:18 MET 2003
$ echo date
date
$ echo `date`
- or -
$ echo $(date)
Wed Feb 26 12:24:18 MET 2003
$ a=1
$ echo ${a}
1
If I am logged in on host A
$ remsh B "echo `hostname`"
$ remsh B "echo $(hostname)"
A
Hmmmm... I would have expected to see "B" here.
Also:
If I am logged in on host A
$ a=1
$ remsh B "a=2 ; echo ${a}"
1
Hmmmm... I would have expected to see "2" here.
Note: exporting is irrelevant in combination with remsh (only with xterms and such).
How am I supposed to port a local script to run remotely ? I can not hold any temporary data. This behaviour limits my possiblilities severely. I do not know / have any means of finding out what the proper approach is.
Please assist.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 03:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 03:49 AM
02-26-2003 03:49 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
try
$ remsh B 'hostname'
B
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 03:53 AM
02-26-2003 03:53 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
how about
remsh B 'echo `hostname`'
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 03:57 AM
02-26-2003 03:57 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
==============================================
#!/bin/sh -p
unset ENV
LOGINSRV=######
PACKAGE=#######
DISPLAY=#######:0.0
# Extract a list of users based on cluster package name
USERLIST=$(ypcat -k auto.user | grep $PACKAGE |awk '{print $1}' 2>/dev/null)
# Launch an xterm
remsh $LOGINSRV 'for USER in $USERLIST
do xterm -display $DISPLAY -e 'sleep 3' &
done'
# If it works, I'll modify the xterm to execute for each user.
==========================================
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 04:05 AM
02-26-2003 04:05 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
unset ENV
LOGINSRV=######
PACKAGE=#######
DISPLAY=#######:0.0
# Extract a list of users based on cluster package name
USERLIST=$(ypcat -k auto.user | grep $PACKAGE |awk '{print $1}' 2>/dev/null)
# Launch an xterm
remsh $LOGINSRV "for USER in $USERLIST;
do; xterm -display $DISPLAY -e 'sleep 3' &;
done"
does this work?
-b-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 04:15 AM
02-26-2003 04:15 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
-Suppose I'm user X on host A
$ remsh B 'for a in X X
> do xterm -title hello -display A:0.0 -e 'sleep 3' &
> done'
This works...
$ USERLIST="X X"
$ remsh B 'for USER in $USERLIST
> do xterm -title hello -display A:0.0 -e 'sleep 3' &
> done'
This doesn't...
Solution:
$ remsh B 'USERLIST="X X" ; for USER in $USERLIST
> do xterm -title hello -display A:0.0 -e 'sleep 3' &
> done'
Case closed, I guess...
What I've learned:
* Use ' instead of " when using remsh to isolate arguments.
* Passing variables through remsh is not possible.
Thank you for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 04:42 AM
02-26-2003 04:42 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
How about:
$ USERLIST="X X"
$ remsh B 'for USER in ' $USERLIST '
> do xterm -title hello -display A:0.0 -e 'sleep 3' &
> done'
Good luck
Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 04:46 AM
02-26-2003 04:46 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
your last comment is not correct:
* Passing variables through remsh is not possible.
$ remsh B 'echo '$USERLIST''
works
It's all a question of quoting.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 04:51 AM
02-26-2003 04:51 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
http://users.evitech.fi/~atrost/Unix/shellfunc.html
It is very important in which order the shell interprets the characters and how you can affect this with quotations.
Chris
Ps: Do you know something about the pointing system in this forum ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 05:22 AM
02-26-2003 05:22 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
Am having difficulties using ' quotes more than once:
#!/bin/sh -p
unset ENV
LOGINSRV=####
remsh $LOGINSRV 'PACKAGE=#####
DISPLAY=#####:0.0
USERLIST="$(ypcat -k auto.user | grep $PACKAGE |awk '{print $1}')"
for USER in $USERLIST
do xterm -title hoi -display $DISPLAY -e 'sleep 3' &
done'
The ' quotes near the awk command are interfering with the remsh ones...
Guess I just don't know how ' quotes are interpreted by the shell...
Will do some homework.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 06:13 AM
02-26-2003 06:13 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
to prevent you working at home try this with your awk:
old: awk '{print $1}'
new: awk '\'{print \$1}\''
Chris
Even if it appears somewhat importunate but maybe you are not logged in, but there are no points assigned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 08:22 AM
02-26-2003 08:22 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
>
>your last comment is not correct:
>
>* Passing variables through remsh is not >possible.
>
>$ remsh B 'echo '$USERLIST''
>
>works
>
>It's all a question of quoting.
>
>Chris
I think Harald means actual variable exportation from the local host to the remote host, not expanding the contents of the local variable and sending that result to the remote command as an argument.
For example;
$ remsh B 'echo '$USERLIST'; printenv'
will print out indeed the content, but the printenv command shows that the variable is NOT set on the remote host.
Then again, I might be wrong :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 10:13 AM
02-26-2003 10:13 AM
Re: working with $(...) and echo ${...} in combination with remsh ??
USERLIST="1 2"
echo ${USERLIST}
remsh xxxx -n "for i in ${USERLIST} ; do echo ${i} ; cd /user/${i}; echo $(hostname); echo ${USERLIST}; pwd ; hostname; done"
remsh xxxx -n "USERLIST="A B" ; for i in ${USERLIST} ; do echo ${i} ; cd /user/${i} ; echo $(hostname) ; pwd ; \ hostname; done"
remsh xxxx -n "USERLIST=\"A B\" ; for i in \${USERLIST} ; do echo \${i} ; \ cd /user/\${i} ; echo \$(hostname) ; echo \${USERLIST}; pwd ; hostname; done"
So you can prevent the shell parsing your variables on your current system before executing the command on the remote system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 12:49 PM
02-26-2003 12:49 PM
Re: working with $(...) and echo ${...} in combination with remsh ??
Just checked my reply on this pages and noticed a few to much backslashes in my reply. I guess due to mistakes while typing. I'll try to correct them, because the \ does the trick.
USERLIST="C D"
echo ${USERLIST}
remsh xxxx -n "for i in ${USERLIST} ; do echo ${i} ; cd /home/${i}; echo $(hostname); echo ${USERLIST}; pwd ; hostname; done"
remsh xxxx -n "USERLIST='A B' ; for i in ${USERLIST} ; do echo ${i} ; cd /home/${i} ; echo $(hostname) ; pwd ; hostname; done"
remsh xxxx -n "USERLIST=\"A B\" ; for i in \${USERLIST} ; do echo \${i} ; cd /home/\${i} ; echo \$(hostname) ; echo \${USERLIST}; pwd ; hostname; done"
For this example i assume the users homedirectory's are in /home and exist on the remote server.
Some explanation:
Putting a \ before a special character prevents it being interpreted on the current host, but send it 'as it is' to the remote host. This way your can pass variables to another system, even if you need qouting '" on the other side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 03:25 PM
02-27-2003 03:25 PM
Re: working with $(...) and echo ${...} in combination with remsh ??
rcp path/script remhost:/path/script
remsh remhost:"/path/script">>localpath/localfile.
Else, you have to do the arcane quoting mechanisms you and the others mention:
remsh somehost:"for I in `ls -l path`;do;echo $I;done".
This is way too much to do on a command line. I enjoy command line scripting, but I'm not insane about it.....
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 10:52 PM
02-27-2003 10:52 PM
Re: working with $(...) and echo ${...} in combination with remsh ??
Here's the *final* version of the script I wrote.
What it does ?
It connects to a number of servers and starts a number of "su -
#!/bin/sh -p
unset ENV
COMMAND="echo \$(hostname) \$(bdf . | grep lvol) ; exit"
for LOGINSRV in A B C D
do
for PACKAGE in $(ypcat auto.user| grep ... | awk -F: '{print $1}' | sort -u)
do
# A remote shell is invoked via remsh
remsh $LOGINSRV -n "for USER in "$(ypcat -k auto.user | grep $PACKAGE | awk '{print $1}')"
do
/usr/bin/timeout -t 100 su - \$USER -c '$COMMAND 2>/dev/null' 2>/dev/null &
done" &
done
done
I still don't know exactly what single quotes (') do, - or better - what the difference is with using backslashes (\)....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2003 11:15 PM
02-27-2003 11:15 PM
Re: working with $(...) and echo ${...} in combination with remsh ??
Nice to hear that your script is working.
I'm working with UNIX for about ten years and from my experience the usage of quotes (single or double) and backslashes (where and how many) is
40% knowledge
30% experience
30% try and error
Have a nice day and a beautiful weekend
Chris