heredoc error check


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting heredoc error check
# 1  
Old 03-16-2011
heredoc error check

Hi,
Is there any way to check the error in heredoc?

Code:

Code:
 
/export/opt/SCssh/3.7.1_C0/bin/sftp -B - csi@192.168.1.100 <<FTP
lcd /WEBSERVER_LINK/data_logs/
ls pub/csidata/GeneralAppFields_8_1_Feed.out
get pub/csidata/GeneralAppFields_8_1_Feed.out
quit
FTP

Now I want to check each and every command's status(SUCCESS/FAILURE) getting success while running. Is there a facility to do error checking in heredoc?
# 2  
Old 03-16-2011
In a word: no.

You will have to write a filter in awk or grep and pipe the output to the filter:
Code:
/export/opt/SCssh/3.7.1_C0/bin/sftp -B - csi@192.168.1.100 <<FTP | grep -q '(cannot|not)'
lcd /WEBSERVER_LINK/data_logs/
ls pub/csidata/GeneralAppFields_8_1_Feed.out
get pub/csidata/GeneralAppFields_8_1_Feed.out
quit
FTP

# status from grep -q
if [ $? -ne 0 ] ; then
  echo 'failure to ftp'
  exit 1;    # return failure to calling script
fi

you get to work on the filter. basically you code will fail gracefully as is, you will not get a new file is all that will happen. You could simply see if you got a new file the file is brand new instead.

Code:
touch dummy
/export/opt/SCssh/3.7.1_C0/bin/sftp -B - csi@192.168.1.100 <<FTP
lcd /WEBSERVER_LINK/data_logs/
ls pub/csidata/GeneralAppFields_8_1_Feed.out
get pub/csidata/GeneralAppFields_8_1_Feed.out
quit
FTP
if [  /WEBSERVER_LINK/data_logs/GeneralAppFields_8_1_Feed.out  -nt  dummy ] ; then
  echo success
else
  echo failure
  exit 1
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Information on heredoc

Hi , I am using ksh on Aix 7.1 and found the below code in a script which is a bit confusing to me, any help will be appreciated <<comments put ${pathforfiles}/${ftpfilename} put ${logs}/${filename}.sch put ${logs}/${filename}.tgr comments I have searched for information on heredoc but... (2 Replies)
Discussion started by: zulfi123786
2 Replies

2. Shell Programming and Scripting

How To Concatenate Two Commands in script using heredoc?

Hello, I am trying to place two commands in heredoc below is the snippet if ;then actionOnTux="$actVerb" else actionOnTux="$actVerb" fi echo "Performing ACTION: $action on $tux@$srv .....\n" if ; then ... (5 Replies)
Discussion started by: kataria.anand
5 Replies

3. Shell Programming and Scripting

Echo multi-line string via heredoc syntax

$ cat bashtest #!/usr/local/bin/bash echo <<<"EOF" line1 line2 line3 EOF $ ./bashtest ./bashtest: line 3: line1: command not found ./bashtest: line 4: line2: command not found ./bashtest: line 5: line3: command not found ./bashtest: line 6: EOF: command not found What am i doing... (4 Replies)
Discussion started by: urello
4 Replies

4. Shell Programming and Scripting

Calling sqlplus from Korn shell heredoc issue

Hi, I am facing an issue wherein some temporary files (here docs) are getting created in /tmp and are not getting deleted automatically. When i check the list of open files with below command i can see one file is getting appended continuously.(In this case /tmp/sfe7h.34p) The output is... (4 Replies)
Discussion started by: Navin_Ramdhami
4 Replies

5. Shell Programming and Scripting

Check error

I have a script is as below , if the output of the script is 0 , then echo abc . script1 if ]; then echo abc fi Can advise if I would like to change it , check the output , if the output only have the wold "0" , then echo abc , if the output have other word , then do nothing , can... (3 Replies)
Discussion started by: ust3
3 Replies

6. Shell Programming and Scripting

Variables in heredoc

I currently use this message to send e-mails in a script but I would also like to save the output of this code to a file as well while preserving the variables. What's the easiest way to accomplish this? #Sending mail notification when=`/bin/date` /usr/sbin/sendmail -t >2 <<-EOM... (2 Replies)
Discussion started by: woodson2
2 Replies

7. Shell Programming and Scripting

Error Check

Hi, I am wirting a script to check the informatica services are running. I am executing a CONFIG FILE before starting the check.. This config file will be having all the ENV Variables..that will be used in the script. I wanted to first check if the Config file has be executed. If its... (4 Replies)
Discussion started by: ch33ry
4 Replies

8. Shell Programming and Scripting

Problem in SFTP using heredoc

Hi, I'm having heredoc to get files from ftp server. #!/bin/bash /export/opt/SCssh/3.7.1_C0/bin/sftp csi@192.168.1.100 <<GET_FILES lcd /WEBSERVER_LINK/data_logs/ ls -l pub/csidata/GeneralAppFields_8_1_Feed.out pub/csidata/CtcCatalog_7_3_3_Feed.out get... (13 Replies)
Discussion started by: bheeshmaraja
13 Replies

9. Shell Programming and Scripting

HEREDOC with fdisk

Hi folks What I'm trying is to build a partitioning script. I can pass a HEREDOC to fdisk just fine. Like this: fdisk /dev/sda << EOF p q EOF but I don't know how to put that HEREDOC into a varible to pass it to fdisk. This is what I have tried so far (no luck) #!/bin/bash ... (3 Replies)
Discussion started by: latenite
3 Replies
Login or Register to Ask a Question