Using rust cmd_lib to replace your bash scripts!

This page summarizes the projects mentioned and recommended in the original post on /r/bash

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • rust_cmd_lib

    Common rust command-line macros and utilities, to write shell-script like tasks in a clean, natural and rusty way

  • #!/usr/bin/env ngs # In response to https://github.com/rust-shell-script/rust_cmd_lib/blob/1f2fc2303db3f467c42589bd944b31834c8a0bca/examples/dd_test.rs # $ ./dd_test.ngs --file /dev/nvme0n1 --block_size 4096 --threads_count 4 # [LOG 2021-03-20 10:57:14 IST] Dropping caches at first # [LOG 2021-03-20 10:57:14 IST] Running command: sudo bash -c echo\ 3\ \>\ /proc/sys/vm/drop_caches # [LOG 2021-03-20 10:57:15 IST] Running with threads: 4, block size: 4096 # [LOG 2021-03-20 10:57:15 IST] Running command: sudo bash -c dd\ if=/dev/nvme0n1\ of=/dev/null\ bs=4096\ skip=1310720\ count=655360\ 2\>\&1 # [LOG 2021-03-20 10:57:15 IST] Running command: sudo bash -c dd\ if=/dev/nvme0n1\ of=/dev/null\ bs=4096\ skip=655360\ count=655360\ 2\>\&1 # [LOG 2021-03-20 10:57:15 IST] Running command: sudo bash -c dd\ if=/dev/nvme0n1\ of=/dev/null\ bs=4096\ skip=1966080\ count=655360\ 2\>\&1 # [LOG 2021-03-20 10:57:15 IST] Running command: sudo bash -c dd\ if=/dev/nvme0n1\ of=/dev/null\ bs=4096\ skip=0\ count=655360\ 2\>\&1 # [LOG 2021-03-20 10:57:22 IST] thread 0 bandwidth: 450 MB/s # [LOG 2021-03-20 10:57:22 IST] thread 1 bandwidth: 451 MB/s # [LOG 2021-03-20 10:57:22 IST] thread 2 bandwidth: 453 MB/s # [LOG 2021-03-20 10:57:22 IST] thread 3 bandwidth: 451 MB/s # [LOG 2021-03-20 10:57:22 IST] Total bandwidth: 1805 MB/s # Command line arguments automatically fed into main() # Default data size - 10G F main(file:Str, block_size:Int=4096, threads_count:Int=1, data_size:Int=10 * 1024 * 1024 * 1024) { log("Dropping caches at first") $(log: sudo bash -c "echo 3 > /proc/sys/vm/drop_caches") log("Running with threads: ${threads_count}, block size: ${block_size}") # Parallel map: each callback runs in it's own thread cnt = data_size / threads_count / block_size results = threads_count.pmap(F(i) { off = cnt * i `log: sudo bash -c "dd if=$file of=/dev/null bs=$block_size skip=$off count=$cnt 2>&1"` }) total_bandwidth = 0 results.each_idx_val(F(i, output) { # "line:" makes the first line of output as the result of `...` bandwidth = `echo $output | line: awk '/MB/ {print $10}'`.Int() log("thread ${i} bandwidth: ${bandwidth} MB/s") total_bandwidth += bandwidth }) log("Total bandwidth: $total_bandwidth MB/s") } # When running without arguments F main() { # exit() - exit code is 1 unless otherwise specified exit("Usage: ${ARGV0} --file FILE [--block_size BLOCK_SIZE] [--threads_count THREADS_COUNT] [--data_size DATA_SIZE]") }

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts