• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Cisco Umbrella

Enterprise network security

  • Free Trial
  • Contact us
  • Blog
  • Login
    • Umbrella Login
    • Cloudlock Login
  • Products
    • Product
      • Cisco Umbrella Cloud Security Service
      • Cisco Umbrella Investigate
      • Product Packages
      • Support Packages
    • Functionality
      • DNS-Layer Security
      • Secure Web Gateway
      • Cloud Access Security Broker (CASB)
      • Interactive Intelligence
      • Cloud-Delivered Firewall
    •  
    • Webinar signup
  • Solutions
    • By Need
      • Protect Mobile Users
      • Fast Incident Response
      • Web Content Filtering
      • Shadow IT Discovery & App Blocking
      • Unified Threat Enforcement
      • Reduce Security Infections
      • Secure Direct Internet Access
      • Securing Remote and Roaming Users
    • By Network
      • Protect Guest Wi-Fi
      • SD-WAN Security
      • Off-Network Endpoint Security
    • By Industry
      • Higher Education Security
      • K-12 Schools Security
      • Healthcare, Retail and Hospitality Security
      • Enterprise Cloud Security
      • Small Business Cybersecurity
      • Our Customers
      • Customer Stories
    • Ransomware Defense for Dummies book
  • Why Us
    • Fast Reliable Cloud
      • Global Cloud Architecture
      • Cloud Network Status
      • Cloud Network Activity
      • Recursive DNS Services
      • Top Reasons to Trial
      • Getting Started
    • Unmatched Intelligence
      • Cyber Attack Prevention
      • Interactive Intelligence
    • Extensive Integrations
      • IT Security Integrations
      • Hardware Integrations
      • Meraki Integration
      • Cisco SD-WAN
    • Navigation-dropdown-promo-free-trial_102820
  • Resources
    • Content Library
      • Top Resources
      • Cybersecurity Webinars
      • Events
      • Analyst Reports
      • Case Studies
      • Customer Videos
      • Datasheets
      • eBooks
      • Infographics
      • Solution Briefs
    • International Documents
      • Deutsch/German
      • Español/Spanish
      • Français/French
      • Italiano/Italian
      • 日本語/Japanese
    • Cisco Umbrella Blog
      • Latest Posts
      • Security Posts
      • Research Posts
      • Threats Posts
      • Product Posts
      • Spotlight
    • For Customers
      • Support
      • Customer Success Hub
      • Umbrella Deployment Hub
      • Customer Success Webinars
      • What’s New
      • Cisco Umbrella Studio
  • Trends & Threats
    • Market Trends
      • Rise of Remote Workers
      • Secure Internet Gateway (SIG)
      • Secure Access Service Edge (SASE)
    • Security Threats
      • Ransomware
      • Cryptomining Malware Protection
      • Cybersecurity Threat Landscape
    •  
    • Navigation-dropdown-promo-threat-report_020521
  • Partners
    • Channel Partners
      • Partner Program
      • Become a Partner
    • Service Providers
      • Secure Connectivity
      • Managed Security for MSSPs
      • Managed IT for MSPs
    •  
    • Become a partner
  • Free Trial Signup
  • Umbrella Login
  • Cloudlock Login
  • Contact Us
Security

The (Very Short) Tale of Unix's Tee Command

By Michael Merritt
Posted on October 6, 2015
Updated on May 27, 2020

Share

Facebook0Tweet0LinkedIn0

“Tee”-ing Off

In Unix, the Tee command is used to ‘T’, or split, the output of a stream into two identical streams. This can be useful for many things, such as writing to a file while also writing to stdout:

$whoami | tee /tmp/file
 ubuntu

This left us with a file that we can later use:

$cat /tmp/file
 ubuntu

Tee can also be used to debug a string of piped commands when you don’t want to disrupt the pipe:

cat console.log | grep 'config' | tee /tmp/file | sort -n | uniq -c

Now you can cat/tmp/file and see what was happening between grep and sort.

And Now For a Short Story

One day at the OpenDNS office, we notice that our Jenkins CI build server was reporting all builds as success — even though they were actually failing! If you’re new to Tee, it might not be immediately apparent what went wrong:

./build.sh | tee console.log

The problem here is that the pipe to Tee replaces the exit code of the command with that of Tee. Tee always exits 0 — it always successes. So, in order to catch the failure you can use PIPESTATUS in bash:

./build.sh  | tee console.log; test ${PIPESTATUS[0]} -eq 0

Since we are calling index[0] of PIPESTATUS, this will give us the exit code of our build.sh script. Be aware that when using multiple pipes,  you’ll need to check the status of each one to determine which pipe failed.
Finally, we’re using the command test -eq 0 to compare equality between the PIPESTATUS exit code and zero — if true, then that means our build script exited successfully this time.
If there are multiple commands happening and you’re still not getting the exit code you expect, then it might make sense to wrap everything in a bash script and use set -e, which will force the script to exit upon an non-zero exit code. Just remember that set -e has some gotchas, and it’s probably better to use a trap to catch the signal and exit appropriately.

Previous Post:

Previous Article

Next Post:

Next Article

Follow Us

  • Twitter
  • Facebook
  • LinkedIn
  • YouTube

Footer Sections

What we make

  • Cloud Security Service
  • DNS-Layer Network Security
  • Secure Web Gateway
  • Security Packages

Who we are

  • Global Cloud Architecture
  • Cloud Network Status
  • Cloud Network Activity
  • OpenDNS is now Umbrella
  • Cisco Umbrella Blog

Learn more

  • Webinars
  • Careers
  • Support
  • Cisco Umbrella Live Demo
  • Contact Sales
Umbrella by Cisco
208.67.222.222+208.67.220.220
2620:119:35::35+2620:119:53::53
Sign up for a Free Trial
  • Cisco Online Privacy Statement
  • Terms of Service
  • Sitemap

© 2021 Cisco Umbrella