0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

bashスクリプト

Last updated at Posted at 2025-02-18

事前知識

ルールとして素晴らしい

echoの動き

#DISK容量の情報を変数に格納
[root@centos8_1 ~]# DISKSIZE=$(LANG=C df)
[root@centos8_1 ~]#

#echoの動作の違いを確認してみよう

#改行コードなしで1行で出てくる

[root@centos8_1 ~]# echo ${DISKSIZE}
Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 1883360 0 1883360 0% /dev tmpfs 1912824 16 1912808 1% /dev/shm tmpfs 1912824 17620 1895204 1% /run tmpfs 1912824 0 1912824 0% /sys/fs/cgroup /dev/mapper/cs-root 26631472 8026144 18605328 31% / /dev/sda2 1038336 240896 797440 24% /boot /dev/sda1 613184 7404 605780 2% /boot/efi tmpfs 382564 12 382552 1% /run/user/42 tmpfs 382564 0 382564 0% /run/user/0

#変数をダブルクォーテーションで囲むと改行が追加される

[root@centos8_1 ~]# echo "${DISKSIZE}"
Filesystem          1K-blocks    Used Available Use% Mounted on
devtmpfs              1883360       0   1883360   0% /dev
tmpfs                 1912824      16   1912808   1% /dev/shm
tmpfs                 1912824   17620   1895204   1% /run
tmpfs                 1912824       0   1912824   0% /sys/fs/cgroup
/dev/mapper/cs-root  26631472 8026144  18605328  31% /
/dev/sda2             1038336  240896    797440  24% /boot
/dev/sda1              613184    7404    605780   2% /boot/efi
tmpfs                  382564      12    382552   1% /run/user/42
tmpfs                  382564       0    382564   0% /run/user/0

ディスクサイズ確認スクリプト

[root@centos8_1 ~]# cat df.sh
#!/bin/bash

LANG=C

WAR=80

DISKSIZE=$(df)

echo "${DISKSIZE}" | grep '/dev'> df.txt


while read  FILESYS BLOCK USED AVAIL USE MOUNT
do

    if [[ ${USE%\%} -lt ${WAR} ]] ; then

        echo "GOOD"

    else

        echo "DISK SPACE ${USE}"

    fi



done < df.txt




やっぱりセンスがない(笑)

#!/bin/bash

while read line

do

numnum=`expr ${line} - 1`

STR=`sed -n ${numnum}p xyq.txt`


if [[ "$STR" != "zzz" ]];
then

  echo ${line}

fi


done < num.txt

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?