Advertisement
danielcristho

minute_log.sh

Mar 21st, 2024 (edited)
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ ! -d "metrics" ]; then
  4. mkdir -p "/home/{user}/metrics"
  5. fi
  6.  
  7. MEMORY="$(free | awk '/Mem:/ {printf "%s,%s,%s,%s,%s,%s", $2,$3,$4,$5,$6,$7}')"
  8. SWAP="$(free | awk '/Swap:/ {printf "%s,%s,%s", $2,$3,$4}')"
  9. STORAGE="$(du -sh /home/{user}/ | awk '{printf "%s,%s",$2,$1}')"
  10.  
  11.  
  12. OUTPUT=$(date "+%EY%m%d%H%M%S")
  13.  
  14. echo "mem_total,mem_used,mem_free,mem_shared,mem_buff,mem_available,swap_total,swap_used,swap_free,path,path_size" > /home/{user}//metrics_$OUTPUT.log
  15. echo "$MEMORY,$SWAP,$STORAGE" >> /home/{user}/metrics/metrics_$OUTPUT.log
  16.  
  17. chmod u+x ./minute_log.sh
  18. chmod 400 /home/{user}/metrics/metrics_$OUTPUT.log
  19.  
  20. # * * * * * /home/{user}/minute_log.sh
  21. # B. Crontab nya
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement