How to echo within EOF (here-document)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to echo within EOF (here-document)
# 1  
Old 11-23-2010
How to echo within EOF (here-document)

Code:
ssh $USR@$host /bin/bash  <<\EOF >> ship-error.txt
awk 'BEGIN{f=0} !f { s=$0; sub(/,.+/, "", s); gsub(/[-: ]/, " ", s); t=(systime()-mktime(s)); if(t<=14400) f=1 } f ' /logs/shiperror.log
EOF

I want to use an echo command within the EOF. Is this possible?
something like this: So that it prints the server name first and then awk command results to the ship-error.txt
Code:
ssh $USR@$host /bin/bash  <<\EOF >> ship-error.txt
echo "Server Name: $host" 
awk 'BEGIN{f=0} !f { s=$0; sub(/,.+/, "", s); gsub(/[-: ]/, " ", s); t=(systime()-mktime(s)); if(t<=14400) f=1 } f ' /logs/shiperror.log
EOF

but $host value doesnot appear.

Last edited by Franklin52; 11-23-2010 at 07:10 AM.. Reason: Please use code tags
# 2  
Old 11-23-2010
I hardly ever use here, as it is interpreted too unconditionally/oddly for complex data. I use echo '...'"$..."'...' | ....

Why the \ in the <<EOF? Oh, you are turning off expansions like $host!

Here Documents
# 3  
Old 11-23-2010
Code:
Instead of
echo "Server Name: $host" 
Try
echo "Server Name: $(uname -n)"

# 4  
Old 11-23-2010
Yes, even if .profile sets $host, ssh does not run it except if you command it explicitly. Sometimes, when using a remote script or complex command or installed application, its
Code:
ssh2 user@remot '. ./.profile;command args'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Here document inside a here document?

Can we use a here document inside a here document? Something like this ssh user@remotehost << REMOTE sudo vserver vsernamename enter << VSERVER perform actions on vserver. VSERVER REMOTE (6 Replies)
Discussion started by: mnanavati
6 Replies

2. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

3. Shell Programming and Scripting

Oracle Shell script | here document `EOF' unclosed

Hi folks I m creating script which is give me below error. $ ./function.ksh ./function.ksh: here document `EOF' unclosed Inside the script is #!/bin/ksh export ORACLE_SID=OECDV1 export ORACLE_HOME=/u01/app/oracle/product/10.2.0 export PATH=$ORACLE_HOME/bin:$PATH echo "sql is... (3 Replies)
Discussion started by: tapia
3 Replies

4. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

5. Shell Programming and Scripting

confused with << EOF EOF

Hi friends , I am confused with << EOF EOF Most of the cases I found sqlplus $db_conn_str << EOF some sql staments EOF another exapmle is #!/bin/sh echo -n 'what is the value? ' read value sed 's/XXX/'$value'/' <<EOF The value is XXX EOF (1 Reply)
Discussion started by: imipsita.rath
1 Replies

6. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

7. Shell Programming and Scripting

here document `EOF' unclosed

I am trying to assign the value in variable using below command. exp_stat=`sqlplus -silent USER_NAME/PWD <<EOF set pagesize 0 feedback off verify off heading off echo off select count(*) from TABLE_NAME; exit; EOF` But getting the below error. here... (2 Replies)
Discussion started by: gander_ss
2 Replies

8. UNIX for Dummies Questions & Answers

\n after EOF

Hello all, I have unix file that ends with the following EOF '9999999999' I want to remove the '\n' character after EOF. What is the command that should be included in the script, before sending the file? will this work: $ echo "<99999999999>\c" >> <filename> thanks in advance. (3 Replies)
Discussion started by: priya12
3 Replies

9. Shell Programming and Scripting

echo with a here-document

I do not know how valid this post is, but here it is. I was writing a script for testing some development code that I had written. It involved many echo statements to redirect the output into a log file. Given the large number of echo statements, I took to this solution cat <<EOF >>... (2 Replies)
Discussion started by: vino
2 Replies

10. Shell Programming and Scripting

EOF use

Hi, I'd like to access a windows directory from aix with samba client. To allow direct access (not interactive), i'm using EOF like: smbclient \\\\winserver\\windir 'passwd' -U usersmb << EOF cd subwindir put myfile EOF The access is correct but does somebody know how to trap errors... (1 Reply)
Discussion started by: jo_aze
1 Replies
Login or Register to Ask a Question