Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:10:32+00:00 2026-06-06T15:10:32+00:00

Redis: 2.0.4, 2.4.1, … I’m going to write a Nagios plugin to check the

  • 0

Redis: 2.0.4, 2.4.1, …

I’m going to write a Nagios plugin to check the length of a list. Here’s my script:

#!/bin/sh

help()
{
    echo "Usage: $0 <host> <port> <key> -w <warning> -c <critical>"
}

case "$1" in
    --help)
        help 
        exit
        ;;
esac

if [ $# -eq 0 ]; then
    help
    exit 3
fi
if [ $# -ne "7" ]; then
    help
    exit 4
fi
if [ $4 !="-w" -o $6 !="-c" ]; then
    help
    exit 5
fi

REDIS_CLI="/usr/local/redis/bin/redis-cli"
LLEN=`$REDIS_CLI -h $1 -p $2 llen $3 | awk '{ print $2 }'`
if [ $LLEN -lt $5 ]; then
    echo "$3.llen:$2 OK - $LLEN | $3.llen:$2=$LLEN;$5;$7"
    exit 0
elif [ $LLEN -ge $5 -a $LLEN -lt $7 ]; then
    echo "$3.llen:$2 WARNING - $LLEN | $3.llen:$2=$LLEN;$5;$7"
    exit 1
elif [ $LLEN -ge "$7" ]; then   
    echo "$3.llen:$2 CRITICAL - $LLEN | $3.llen:$2=$LLEN;$5;$7"
    exit 2
fi

but I got the following error when running /usr/lib64/nagios/plugins/redis_llen.sh 192.168.5.201 2468 -w 90000 -c 100000:

/usr/lib64/nagios/plugins/redis_llen.sh: line 31: [: -lt: unary operator expected
/usr/lib64/nagios/plugins/redis_llen.sh: line 34: [: too many arguments
/usr/lib64/nagios/plugins/redis_llen.sh: line 37: [: -ge: unary operator expected

Running it in debug mode, I found that the LLEN‘s value is… blank. Since the llen queue_1 returns the right result:

# /usr/local/redis/bin/redis-cli -h 192.168.5.201 -p 2468 llen queue_1
(integer) 965

why does the pipeline swallow my fields? (not only to awk but also echo, tee, …):

# /usr/local/redis/bin/redis-cli -h 192.168.5.201 -p 2468 llen queue_1 | \
awk '{ print $0 }'
961

I can check the number of fields and print the corresponding as a workaround:

| awk '{ if (NF == 2) print $2; else print $1 }'`

but I really want to know why does it happen? Is there any null or special character between (interger) and the number?

PS: it seems that some other Redis version (for e.x: 1.3.7) doesn’t get this issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:10:35+00:00Added an answer on June 6, 2026 at 3:10 pm

    What you’re experiencing is redis-cli selecting different outputs depending on what STDOUT is. If STDOUT is a TTY, redis-cli will output using it’s “standard” formatting. Otherwise, the “raw” formatting is the default:

    --raw            Use raw formatting for replies (default when STDOUT is not a tty)
    

    As you see from the help, or the above, you can specify --raw to always have it output the “raw” format (without type qualifiers, etc). What I found out digging through the source for this, is that there is also a CSV mode, using redis-cli --csv.

    Edit: To force the “standard” output, even when STDOUT is not a TTY, you can set the environment variable FAKETTY:

    FAKETTY=1 redis-cli llen some_list | awk '{ print $2 }'
    

    Or

    redis-cli --raw llen some_list | awk '{ print $1 }'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using redis-rb, how can I push a hash into a list? Do I have
Redis (a key-value store) supports lua scripts - it executes the script on the
I have simple redis list key => supplier_id Now all I want it retrieve
I am using redis List for storing a list of users. I want to
In a redis datastore I have a list of keys, I want to iterate
I tried to run Redis-Sharp test program. It sets the string length when I
I'm new to redis, I'm storing a list in redis through erlang but I
I want to write a ueberDB Redis-Handler for my Etherpad. I absolutely do not
I am using redis to store an ordered set of items. Here is a
after shutting down the redis server, the values stored using set is destroyed, here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.