Coder Social home page Coder Social logo

linux's Introduction

Linux

display_help() { echo "Usage: internsctl [OPTIONS] COMMAND" echo "Options:" echo " --help Display this help message" echo " --version Display command version" echo "" echo "Commands:" echo " cpu getinfo Display CPU information" echo " memory getinfo Display memory information" echo " user create Create a new user" echo " user list List all users" echo " user list --sudo-only List users with sudo permissions" echo " file getinfo Display file information" echo "" echo "For more information on a specific command, use:" echo " internsctl COMMAND --help" }

Function for the --version option

display_version() { echo "internsctl v0.1.0" }

Function to get CPU information

get_cpu_info() { lscpu }

Function to get Memory information

get_memory_info() { free }

Function to create a new user

create_user() { if [ $# -ne 1 ]; then echo "Usage: internsctl user create " return 1 fi sudo adduser "$1" }

Function to list users

list_users() { cut -d: -f1 /etc/passwd }

Function to list users with sudo permissions

list_sudo_users() { grep -Po '^sudo.+:\K.*$' /etc/group | tr ',' '\n' }

Function to get file information with specific options

get_file_info() { local option="$1" local file="$2"

if [ "$option" == "--size" ]; then
    stat -c %s "$file"
elif [ "$option" == "--permissions" ]; then
    stat -c %A "$file"
elif [ "$option" == "--owner" ]; then
    stat -c %U "$file"
elif [ "$option" == "--last-modified" ]; then
    stat -c '%y' "$file"
else
    echo "Invalid option: $option"
    return 1
fi

}

Main script logic

case "$1" in "--help") display_help ;; "--version") display_version ;; "cpu") case "$2" in "getinfo") get_cpu_info ;; *) display_help ;; esac ;; "memory") case "$2" in "getinfo") get_memory_info ;; *) display_help ;; esac ;; "user") case "$2" in "create") create_user "$3" ;; "list") if [ "$3" == "--sudo-only" ]; then list_sudo_users else list_users fi ;; *) display_help ;; esac ;; "file") case "$2" in "getinfo") if [ $# -lt 3 ]; then echo "Usage: internsctl file getinfo [OPTIONS] " exit 1 fi get_file_info "$3" "$4" ;; *) display_help ;; esac ;; *) display_help ;; esac

End of script

linux's People

Contributors

sunnykrp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.