Skip to content
Branch: master
Find file Copy path
executable file 77 lines (64 sloc) 2.13 KB
# bashreadline Print entered bash commands from all running shells.
# For Linux, uses BCC, eBPF. Embedded C.
# USAGE: bashreadline [-s SHARED]
# This works by tracing the readline() function using a uretprobe (uprobes).
# When you failed to run the script directly with error:
# `Exception: could not determine address of symbol b'readline'`,
# you may need specify the location of library
# with `-s` option.
# Copyright 2016 Netflix, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
# 28-Jan-2016 Brendan Gregg Created this.
# 12-Feb-2016 Allan McAleavy migrated to BPF_PERF_OUTPUT
from __future__ import print_function
from bcc import BPF
from time import strftime
import argparse
parser = argparse.ArgumentParser(
description="Print entered bash commands from all running shells",
parser.add_argument("-s", "--shared", nargs="?",
const="/lib/", type=str,
help="specify the location of library.\
Default is /lib/")
args = parser.parse_args()
name = args.shared if args.shared else "/bin/bash"
# load BPF program
bpf_text = """
#include <uapi/linux/ptrace.h>
struct str_t {
u64 pid;
char str[80];
int printret(struct pt_regs *ctx) {
struct str_t data = {};
u32 pid;
if (!PT_REGS_RC(ctx))
return 0;
pid = bpf_get_current_pid_tgid(); = pid;
bpf_probe_read(&data.str, sizeof(data.str), (void *)PT_REGS_RC(ctx));
return 0;
b = BPF(text=bpf_text)
b.attach_uretprobe(name=name, sym="readline", fn_name="printret")
# header
print("%-9s %-6s %s" % ("TIME", "PID", "COMMAND"))
def print_event(cpu, data, size):
event = b["events"].event(data)
print("%-9s %-6d %s" % (strftime("%H:%M:%S"),,
event.str.decode('utf-8', 'replace')))
while 1:
except KeyboardInterrupt:
You can’t perform that action at this time.