Using EOF do/for script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using EOF do/for script
# 1  
Old 12-06-2012
Using EOF do/for script

I am trying to ssh to a remote server Using an EOF script and run a do/for loop. I have been able to do the following:

Code:
su nbadmin -c "ssh -t sever1 exec /bin/sh -s"<<EOF
/etc/script/lister -C DAVID1 --s 12/01/2012 -e 12/03/2012 /volume
EOF`

This works just fine. But I want to run a script like this:

Code:
for server in server1; 
do 
     su nbadmin -c "ssh -t $server  \
       'for DAVID1  in `cd /tmp/image; 'ls'`;
       do 
            if '[ -d  /tmp/image/DAVID1  ]'; then 
               echo "host case is correct";
                break;
       else 
              echo "not correct";
              break;
      fi;
done'"

Is this possible? If so how would you do it? I am having problems maintaining the ssh session and running complete command. So I thought I would try EOF but am not aware of this would work
Moderator's Comments:
Mod Comment code tags please -- separated hard to read code blobs into lines

Last edited by jim mcnamara; 12-06-2012 at 03:46 PM..
# 2  
Old 12-06-2012
First off, consider your task. You seem to want to find the location of a directory on a server. This is a one time deal usually, which is why you ran it all into one line.

If I understand what you want:
Code:
for server in server1 server2 server3
do
    echo "$server..."
    dir=$(su - nbadmin -c "ssh $server ' find /tmp/image -type d' " )
    [ -z "$dir" ]  && echo "bad" || echo "good"
done

Some of your code does not make sense, but this is what I kinda think you want.
# 3  
Old 12-06-2012
Thanks! this helped. I will check it out when I have a minute
# 4  
Old 12-09-2012
Thank you!

Thanks, Jim! I was easily able to adapt your script to my needs and I've learned a lot!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Trapping a kill command sent to a script and using it to send an EOF to a subprocess before killing

I originally had a script written in pure shell that I used to parse logs in real time and create a pipe delimited file that only contained errors. It worked but it was using a lot of memory (still not clear on why). I originally got around this by writing a wrapper for the script that ran on cron... (1 Reply)
Discussion started by: DeCoTwc
1 Replies

2. UNIX for Dummies Questions & Answers

multiple if conditions and EOF in a shell script

I want to create an IF condition with multiple condition, in the statement below I want to add OR EOF, can any one please advise how to do. if } != $sample ] && ; then echo ..... fi code tags please (1 Reply)
Discussion started by: analyst
1 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. 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

5. Shell Programming and Scripting

What is << EOF

I'm trying to connect to oracle with the following code in the script: checksqlerror{ if echo $1 exit fi } $SQLPLUS username/password@schemaname checksqlerror "failed to connect to oracle" If I'm passing wrong schema name,instead of executing checksqlerror it stops and expects user... (2 Replies)
Discussion started by: BhawanaAggarwal
2 Replies

6. Shell Programming and Scripting

command << EOF(dont want to call other script)

Dear Freinds, Help needed in input redirection . My problem is as follows.. I have a shell script as follows which calls another gnuplot script . datagen.sh #!/bin/ksh gnuplot plot_I.plt In the above file I am calling another file called plot_I.plt which reside in the same... (4 Replies)
Discussion started by: user_prady
4 Replies

7. 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

8. Shell Programming and Scripting

Check EOF in shell script

Hi, I need to check whether one file has EOF or not. There's one daemon in our system, which will pick the files FTPed to us. However, sometimes the daemon picks the file before FTP is finished. So I'm planning to add some checking of EOF on the FTPed files in the shell script. Could... (8 Replies)
Discussion started by: ideazhcy
8 Replies

9. UNIX for Dummies Questions & Answers

Eof

hello all, how end of a file is detected in UNIX system? does it make use of any special symbols to identify the EOF? :( thank you all (5 Replies)
Discussion started by: compbug
5 Replies

10. Shell Programming and Scripting

Please help with EOF

Hello, you are an awesome crowd! You answered my last questions, thank you sooo much! I am trying to write a korn shell script that will record the memory my application is using (HP-UX B.11.11) and I have this: if (( $APP > $THRESHOLD )) then echo "Warning message will display" cat... (2 Replies)
Discussion started by: satraver
2 Replies
Login or Register to Ask a Question