1. Write a script “ between ” to display the files whose sizes are in a specific
ID: 3696621 • Letter: 1
Question
1. Write a script “between” to display the files whose sizes are in a specific range. This script takes two arguments as the lower bound and upper bound of the file size, and prints out a list of filenames as well as their sizes. For example, for the following files
$ls -l
--- 79 --- bb2
--- 96 --- birthday --- 198 --- bothfiles --- 152 --- bundle --- 115 --- dateset
If we execute “./between 80 120”, the output should be birthday: 96 bytes
dateset: 115 bytes
(Script must be created utilizing awk)
2. Write a script “menu_size” which provides a menu interface with three options: 1. Set the upper bound
2. Set the lower bound
3. Search
4. Quit
When the user chooses 3, the script “between” in question 1 will be executed. The two arguments of “between” can be set with option 1 and 2. The script will go back to the menu selection after a search, and terminates only when the user selects option 4.
Explanation / Answer
//Script 1(a script “between” to display the files whose sizes are in a specific range. This script takes two arguments as the lower bound and upper bound of the file size, and prints out a list of filenames as well as their sizes. For example, for the following files)
#!/bin/bash
#Shell script to Capture the file name and size
# Script to display the files whose sizes are in a specific range
#take the file
FILENAME=/home/heiko/dummy/package.txt
#take the file size
FILESIZE=$(stat -c%s "$FILENAME")
#print the file size
echo "Size of $FILENAME = $FILESIZE bytes."
#taking the two argumnets
# sh scriptname 1 2
taking first as lowerbound
echo lower bound: $1
#taking second as uperbound
echo upper bound: $2
#seting value of the lower bound
$1 lowerbound=0
#setting value of the uperbound
$2 upper bound=500
echo "File Name,Size,date" > /tmp/output_file
ls -l --time-style=+%m.%d.%Y /path/to/file |grep -v "^total|^d"|awk '{print $NF","$4","$5 }'
Script 2-(a script “menu_size” which provides a menu interface with three options: 1. Set the upper bound
2. Set the lower bound
3. Search
4. Quit
)
#!/bin/sh
(
echo "menu"
echo "10" ; sleep 1
echo "# set upperbound" ; sleep 1
echo "20" ; sleep 1
echo "# set lowerbound" ; sleep 1
echo "50" ; sleep 1
echo "search" ; sleep 1
echo "75" ; sleep 1
echo "#quit " ; sleep 1
echo "100" ; slee
) |
zenity --progress
--title="set upperbound"
--text="uperbound is set..."
--percentage=0
zenity --progress
--title="set lower bound"
--text="lowerbound is set is set..."
--percentage=0
zenity --progress
--title="searh"
--text="searching the files..."
--percentage=0
zenity --progress
--title="Quit"
--text="out of the system..."
--percentage=0
if [ "$?" = 0 ] ; then
zenity --progress
--text="uperbound set."
elif
--text="uperbound not set."
fi
if [ "$?" = 0 ] ; then
zenity --progress
--text="lowerbound set."
elif
--text="lowerbound not set."
fi
if [ "$?" = 0 ] ; then
zenity --progress
--text="search found."
elif
--text="file not found."
fi
if [ "$?" = 0 ] ; then
zenity --progress
--text="quit."
elif
--text="not able to quit"
fi
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.