Instead of displaying whole df command output i Wrote below script to find only if disk space crosses threshold (here i assuming threshold as 90%) and also included current memory usage percentage details
Here is the code
df -Ph| awk 'NR>1'| sed "s/%//g"| awk '($(NF-1) >90){print "Disk space utilized is" " "$(NF-1)"%" " for partition" " "$NF}'|sed '1i Below are partition details of hosts where disk utilized crossed 90%\n'| sed '$s/.*/&\n=============================================================================/g';free | awk '/Mem/{print $0}'| awk '{print $3/$2*100}'| sed '1i below are current memory usage percentage of host'
Sample output
Below are partition details of hosts where disk utilized crossed 90%
Disk space utilized is 100% for partition /snap/gnome-system-monitor/51
Disk space utilized is 100% for partition /snap/gtk-common-themes/1122
Disk space utilized is 100% for partition /snap/core/6531
Disk space utilized is 100% for partition /snap/gnome-calculator/260
Disk space utilized is 100% for partition /snap/gnome-logs/37
Disk space utilized is 100% for partition /snap/gtk-common-themes/818
=============================================================================
below are current memory usage percentage of host
39.2084
Я не вижу здесь необходимости в awk:
#!/bin/bash
while IFS=, read -r user pass; do
# something with "$user" "$pass"
done < path/to/file.csv
Предположим, у вас есть несколько хороших паролей.:
user1,",3 ""e`$^~´"
user2,""")& Eu`id`"
user3,ThisIsAlsoAGoodPasswordBecauseItIsLong
Тогда вам нужно что-то, что может анализировать CSV ("" внутри " есть " ).
cat user+password.csv | parallel --csv do_stuff {1} {2}
Если файл является правильным CSV-файлом, вы можете использовать ksh93
вместо bash
, который поддерживает синтаксический анализ CSV-файлов:
#! /usr/bin/env ksh93
while IFS=, read -rS user password; do
something with "$user" and "$password"
done
При вводе типа
user,"a""b
c,d"
Это правильно установило бы $user
на user
и $password
на a"b<LF>c,d
.