Hello, i'm trying to solve this script.
List, one at a time, all files larger than 100K in the /home/username directory tree. Give the
user the option to delete or compress the file, then proceed to show the next one. Write to a
logfile the names of all deleted files and the deletion times.
I made this pseudocodebut i don't think i'm getting anywhere near of what my script is supposed to do, can anyone help me solve this?
Pseudocode:
#!/bin/bash
for $filename in (~)
skip if size(~) < 100K
display $filename
echo = "Delete or compress?"
if response == "delete"
rm $nombre
$nombre + time >> log.txt
else if response == "compress"
zip $nombre.zip $nombre
Welcome to forum, kindly use code tags while posting codes/commands in your post. Here is the script which may help you in same. please let us know if you have any queries on same too.
#####MAIN script ######
cat check_files.ksh
BA=`find -type f | awk '{gsub(/\.\//,X,$0);print $0}'`
for i in $BA[@]
do
echo $i
./check_files1.ksh $i
done
###### Other second script called in first script #####
cat check_files1.ksh
echo "Do you want to delete or zi the file"
read choice;
FILENAME=$1;
echo $FILENAME is file
case "$choice" in
"delete") echo "$FILENAME" >> LOGS_files_deleting
rm "$FILENAME"
;;
"zip") echo "File is zipping now."
gzip "$FILENAME"
;;
*) echo "wrong option:"
exit
;;
esac
### Run it as follows ###
./check_files.ksh
You are using variables that haven't been defined, using variables incorrectly, and do not seem to want to allow a user to keep a large file.
Why are you writing pseudocode instead of actual bash code with comments or echo statements indicating what the code you still need to complete is supposed to do.
No, it's not homework, i'm trying to solve this pool of scripts to try to learn to code in bash, but i'm just starting to, so i'm looking for some help to begin with since i'm not that experienced coding in bash.
@pilnet101, please review your posting!
What is your second find for?
Then, sort +6 is deprecated, get used to sort -k7 !
Last but not least, you better replace
if [[ -z "$file" ]]; then
echo "Invalid choice!"
else
break
fi
because an non-zero exit state in the && branch will continue the || branch,
while a non-zero exit state in the then branch will never go to the else branch.