1

I'm confused on how to get the data usage information into the variables to determine if the file size are acceptable. How do I make the variable and direct it to the rest of the script?

Write a script (called passwd_size.sh) that does these tasks:

  • Find the size of the /etc/passwd file
  • If the size is greater than 2000 bytes, display a message that the file exceeds size, otherwise, display message that the file is within the size limit.

du -c "/etc/passwd"
num=0
if [ $num -gt 2000 ];
then
echo "File exceeds size limit."
fi
if [ $num -lt 2000 && -eq 2000  ];
then
echo "File is within size limit."
fi

Any help is greatly appreciated!!!

DSH72
  • 313

1 Answers1

3
#!/bin/sh

file=/etc/passwd

minimum=2000

actual=$(wc -c <"$file")

if [ $actual -ge $minimum ]; then

echo The file size is bigger $minimum bytes

else

echo The file size is less  $minimum bytes

fi
shamsky
  • 104