Pipe causing last command error to not function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pipe causing last command error to not function
# 1  
Old 11-03-2014
Pipe causing last command error to not function

Hi

I am quite new to scripting and cannot work out how to do the following -

I want to pipe to a log file and then use the "last statement error" in an if statement after, and this doesn't work because it checks the pipe statement instead of the script.

Example:
Code:
executteTheScript $var | tee $LOG
if[[ $? != 0 ]]
...

So even if executeTheScript fails, the if statement doesn't pick it up because tee passes - does anyone know how to solve this issue?

Thanks

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks
# 2  
Old 11-03-2014
Does the script log any text that could be used as a pass/fail flag?
# 3  
Old 11-03-2014
You could also break it up:

Code:
if ! executteTheScript $var
then
        cat $log
        handleerror
else
        cat $log
fi

# 4  
Old 11-03-2014
First of all, did you know that your log will only contain the standard output stream (stdout)?

Use yourscript $var 2>&1 | tee $LOG to capture the standard error (stderr) stream too. This might help you with the potential troubleshooting process.

In bash, there is a special internal array variable called $PIPESTATUS, which may work relatively reliable for the simple case you mention.

${PIPESTATUS[0]} should hold the exit status of the first command in the pipe.

Source: Internal Variables
This User Gave Thanks to junior-helper For This Post:
# 5  
Old 11-03-2014
Thanks guys

I fixed it by splitting the two commands - there was probably a better was to do it, but it works and that's all I need right now!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Function in one-linef and pass arguments in a pipe

I need to declare a function, this function will contain a script, this script cannot be in a file but must be piped. and then, for the script to run, i need to pass arguments to it. everything has to be on one line. so i'm basically looking for a one-liner here's what i'm doing: myfunc ()... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

While loop is causing ssh command to exit from script after first iteration.

I am trying to check multiple server's "uptime" in a loop over "ssh". When I execute multiple ssh commands with hard coded servernames script is executing fine. But when I pass server names using while loop, script is exiting after checking first server's status, why? # serverList... (8 Replies)
Discussion started by: kchinnam
8 Replies

3. Shell Programming and Scripting

There's a unknown command on line 1 and i don't know whats causing it.

My OS is Linux GL version 2.4.26. I am trying to make a shell script that outputs a chart displaying info of who is online, boot time, and the real time, I have manage to get it to work, but I still get the error "./user/script: line 1: : command not found." I do in fact have access to root, if... (2 Replies)
Discussion started by: thatguy565
2 Replies

4. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

5. Shell Programming and Scripting

Error Message in function causing failure.....

I have a long busybox ash script that has 3 stages. 1. Identify and Capture information on variable data sources, output the information to text file on each data source. 2. Using data from 1 above now actually do data processing on each individual dataset. 3. Produce report. So... (6 Replies)
Discussion started by: tesser
6 Replies

6. Shell Programming and Scripting

Spaced input causing awk error

Hi all, Just want to say thanks for the great forum you have here, the old topics and posts have helped tremendously. So much so that I have managed to figure a lot out just by researching. However, I'm having a small issue that I simply can't find the answer to. (4 Replies)
Discussion started by: whyte_rhyno
4 Replies

7. UNIX for Dummies Questions & Answers

function and pipe

Hi, Is it possible that the output of a command is piped into a unix function? Just like in below: #!/bin/ksh concat(){ echo Orbix } echo "Hello there" | concat How to manipulate the output of a command inside the function? (2 Replies)
Discussion started by: Orbix
2 Replies

8. Solaris

Memory error causing reboot

Hi there I have a box that at 4pm started recieving soft errors on a DIMM, normally this is ok and we have time to swap it out. But I got the following error which caused the box to reboot NOTE: there were abount 6 or 7 normal "soft error encountered" messages before this one Nov 7... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

9. Solaris

Explorer causing syslog error

Hi there, I have upgraded my explorer (SUNWexplo) on a solaris 10 Sparc box from version 3.4 to the latest version (5.5) . However im a little concerned, whenever I run the new explorer either manually or scheduled, I get a syslog event as follows 1 in 0:08:31: Sep 22 17:00:15 fmy.machine.com... (8 Replies)
Discussion started by: hcclnoodles
8 Replies

10. UNIX for Dummies Questions & Answers

Variable for -name causing issue in Find command

Hi there, I'm trying to find files that are greater then 30 days old, zip them and move to a different directory. I'm encountering an issue passing a variable (FilesToFind) to name within the find command. Here's the code I'm running: #! /usr/bin/sh FileDir=/home/ariba... (2 Replies)
Discussion started by: ParNone
2 Replies
Login or Register to Ask a Question