[CentOS] Basic Bash Script Question
I'm stuck trying to work this one out and my Google skills are apparently lacking today. This is a test bash script; #!/bin/bash do something | tee a.log if [ $? -ne 0]; then echo broken fi The problem with this script is $? contains the exit value of the tee command, but I want to check the exit value of whatever command I put in place of 'do something'. How can I achieve this without loosing the tee operation, as 'do something' maybe a long running command with a lot of output like rsync? I don't want to; result=`do something` if [ $? -ne 0... fi echo $result As that won't output anything until the script has finished (the reason for the tee is that this script will be a scheduled cron tab but it may be run interactively sometimes also). Thanks for reading :) -- James. http://www.jamesbensley.co.cc/ There are 10 kinds of people in the world; Those who understand Vigesimal, and J others...? ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] Basic Bash Script Question
Le lun 21 fév 2011 10:31:38 CET, James Bensley a écrit: I'm stuck trying to work this one out and my Google skills are apparently lacking today. This is a test bash script; #!/bin/bash do something | tee a.log if [ $? -ne 0]; then echo broken fi What about : { do something ; RETCODE=$? ; } | tee somefile echo $RETCODE -- Philippe ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] Basic Bash Script Question
2011/2/21 James Bensley jwbens...@gmail.com: I'm stuck trying to work this one out and my Google skills are apparently lacking today. This is a test bash script; #!/bin/bash do something | tee a.log if [ $? -ne 0]; then echo broken fi The problem with this script is $? contains the exit value of the tee command, but I want to check the exit value of whatever command I put in place of 'do something'. How can I achieve this without loosing the tee operation, as 'do something' maybe a long running command with a lot of output like rsync? I don't want to; result=`do something` if [ $? -ne 0... fi echo $result man bash search for Pipelines, pipefail and PIPESTATUS. -- Pascal ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Re: [CentOS] Basic Bash Script Question
On 21 February 2011 11:05, Pascal pax...@gmail.com wrote: man bash search for Pipelines, pipefail and PIPESTATUS. Great, thanks for that, pipefail is exactly what I need :) -- James. http://www.jamesbensley.co.cc/ There are 10 kinds of people in the world; Those who understand Vigesimal, and J others...? ___ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos