Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| linux:bash [2020/10/02 17:33] – admin | linux:bash [2024/02/14 06:45] (current) – [Linux.Bash] admin | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| setopt histreduceblanks | setopt histreduceblanks | ||
| + | </ | ||
| + | |||
| + | <code BASH> | ||
| + | # check xterm color | ||
| + | msgcat | ||
| + | </ | ||
| + | ++++ Пример| | ||
| + | {{: | ||
| + | ++++ | ||
| + | <code BASH> | ||
| + | # grep for configuration without comment line | ||
| + | egrep -v " | ||
| </ | </ | ||
| bash | bash | ||
| Line 45: | Line 57: | ||
| </ | </ | ||
| + | |||
| + | <code BASH> | ||
| + | http -hdo ./body httpbin.org/ | ||
| + | |||
| + | |||
| + | # выделение и формирование объекта | ||
| + | http https:// | ||
| + | # jq grep | ||
| + | jq -r ' | ||
| + | |||
| + | # JQ https:// | ||
| + | # рекурсивно выделить в json объект в имени которого есть " | ||
| + | jq '.. | objects | with_entries(select(.key | contains(" | ||
| + | # same, but output propper array | ||
| + | jq '[ .. | objects | with_entries(select(.key | contains(" | ||
| + | # or | ||
| + | jq 'map( .. | objects | with_entries(select(.key | contains(" | ||
| + | # transform input from {type: a, amount: 1} to {a: 1} and sum all values by type | ||
| + | jq '[ .[] | {(.type): .amount} ] | map(to_entries) | add | group_by(.key) | map({key: .[0].key, value: map(.value) | add}) | from_entries' | ||
| + | # invert selection of contains key name | ||
| + | journalctl -f -o json | jq -cr ' | ||
| + | </ | ||
| + | |||
| + | image magic | ||
| + | <code BASH> | ||
| + | create collage from files | ||
| + | " | ||
| + | </ | ||
| ===== Linux.Admin ===== | ===== Linux.Admin ===== | ||
| + | <code BASH> | ||
| + | # users | ||
| + | $ps auxww | ||
| + | #all full command line | ||
| + | $ps ewwf | ||
| + | </ | ||
| + | |||
| <code BASH> | <code BASH> | ||
| # Get process using swap | # Get process using swap | ||
| Line 67: | Line 114: | ||
| </ | </ | ||
| + | <code BASH> | ||
| + | # monitor directory | ||
| + | watch -n 5 'echo $(date) $(du -d 1 / | ||
| + | </ | ||
| <code BASH> | <code BASH> | ||
| # SWAP INFO | # SWAP INFO | ||
| Line 85: | Line 135: | ||
| # Grep exclude comments and blank lines | # Grep exclude comments and blank lines | ||
| grep -v ' | grep -v ' | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Linux move files ===== | ||
| + | https:// | ||
| + | |||
| + | - scp | ||
| + | - ftp | ||
| + | - rsync | ||
| + | - GridFTP | ||
| + | - BBCP | ||
| + | |||
| + | ===== Scripting ===== | ||
| + | * scripting pitfails https:// | ||
| + | |||
| + | |||
| + | ===== Scripting-code ===== | ||
| + | * read line by line - https:// | ||
| + | |||
| + | <code BASH> | ||
| + | |||
| + | #!/bin/bash | ||
| + | |||
| + | # Declare variables | ||
| + | vm_name="" | ||
| + | vm_path="" | ||
| + | skipped_lines="" | ||
| + | current_line_number=1 | ||
| + | |||
| + | # Read the file line by line | ||
| + | while IFS=';' | ||
| + | # Check if the line has the correct format | ||
| + | if [[ -z " | ||
| + | skipped_lines=" | ||
| + | fi | ||
| + | |||
| + | # Process the variables here if the line has the correct format | ||
| + | if [[ -n " | ||
| + | echo "VM name: $vm_name" | ||
| + | echo "VM path: $vm_path" | ||
| + | fi | ||
| + | |||
| + | # Increment the line number | ||
| + | current_line_number=$((current_line_number+1)) | ||
| + | done < file.txt | ||
| + | |||
| + | # Print the skipped lines | ||
| + | if [[ -n " | ||
| + | echo "The following lines were skipped because they did not have the correct format:" | ||
| + | echo " | ||
| + | fi | ||
| </ | </ | ||