LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using grave accent into rsh script. (https://www.linuxquestions.org/questions/programming-9/using-grave-accent-into-rsh-script-947352/)

beckss 05-29-2012 05:04 AM

Using grave accent into rsh script.
 
Hi gurus!
Can anybody explain me if exist possibility using grave accent with rsh syntax. Here below piece of script ->
[root@noaapp1 ROOT_ACTIVE_CRON]# rsh racdev1 -l oraint ". .bash_profile;
> do
> list_files="1 2 3 4 5 6 7"
> for i in `echo ${list_files}`
> do
> echo $i
> sleep 1
> done "
and I recieved error.
bash: -c: line 1: syntax error near unexpected token `do'
bash: -c: line 1: `do'

Thanks and best regards, Staas.

Nominal Animal 05-29-2012 06:53 AM

Please use [CODE][/CODE] tags around your code. Here is your command, with color and whitespace added for clarity and emphasis:
Quote:

Originally Posted by beckss (Post 4690113)
Code:

rsh racdev1 -l oraint "
    . .bash_profile;
    do
    list_files="1 2 3 4 5 6 7"
    for i in `echo ${list_files}`
    do
        echo $i
        sleep 1
    done "


There are so many errors I don't know where to start.

Quoting: After oraint, you supply 7 parameters to rsh. The first parameter ends with 1, the second parameter is 2, and so on; the final parameter starts with 7. If you do not understand why this is, read the Quoting section in the Bash reference manual.

The first do is an error. There is no reason for it.

Backticks within a double-quoted string: the command within the backticks is run on the current machine, and whatever it yields, is inserted into the double-quoted string before it is given to rsh. Besides, you should be using $(...) instead of `...` (unless the default shell on the remote system is an ancient Unix Bourne shell -- and I don't think so, because you're explicitly sourcing .bash_profile on the remote machine).

for i in $(echo ${variable});: No, do not do that. It applies pathname expansion twice, and you do not want nor need that. Typical use would be for i in ${variable};, where the value of variable will be split and pathname expansion applied, and i will loop over the results.

Finally, are you sure you wish to use rsh and not ssh (with key-based authentication)?

Consider using something like
Code:

ssh -l oraint racdev1 bash -c 'for i in 1 2 3 4 5 6 7; do echo $i; sleep 1; done'
or perhaps
Code:

ssl -l oraint racdev1 bash -c '"list=(1 2 3 4 5 6 7)"'; for i in "${list[@]}" ; do echo "$i" ; sleep 1 ; done'
Both of these execute bash explicitly, just in case the default shell might be something else on the remote machine. The latter uses double quotes to set up the list array in the remote shell, so you can insert variables etc. from the local shell. The actual snippet is in single quotes, so that the local shell will not interpret that part. Both just echo the numbers 1 to 7 one at a time, sleeping for a second in between, running the loop on the remote machine.

beckss 05-29-2012 07:50 AM

Hi!
Thanks you correct. I am not paste proper code.
Please inpect below ->
[root@noaapp1 tmp]# rsh racdev1 ". .bash_profile;
list_files="1 2 3 4 5 6 7"
for i in `echo ${list_files}`
do
echo $i
sleep 1
done"
bash: line 1: 2: command not found

Thanks Staas.

pan64 05-29-2012 08:38 AM

yes, it is the same:
rsh host command
command is now: ". .bash_profile;
list_files="1

described by "some text" and the 1 coming immediately after "
and the following 2 3 4 5 6 .... have no meaning. That's why you got 2: command not found.


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