Professional Documents
Culture Documents
Contents...............................................................................................................................2
Code.....................................................................................................................................3
Output................................................................................................................................10
1
Source Code:
Main Code:-
I.e. – Calendar, Date & Time, Delete File.
#!/bin/bash
local file_list
file_list=$(ls "$directory")
local selected_file
selected_file=$(dialog --title "Select File to Delete" --menu
"Choose a file to delete:" 20 60 10 $(for file in $file_list; do echo
"$file" "$file"; done) 2>&1 >/dev/tty)
if [ -n "$selected_file" ]; then
local confirm_delete
confirm_delete=$(dialog --title "Confirm Deletion" --yesno "Are
you sure you want to delete '$selected_file'?" 8 60 2>&1 >/dev/tty)
if [ $? -eq 0 ]; then
rm -i "$directory/$selected_file"
if [ $? -eq 0 ]; then
dialog --title "File Deleted" --msgbox "'$selected_file' has
been deleted." 8 60
else
dialog --title "Error" --msgbox "Error deleting
'$selected_file'." 8 60
fi
fi
2
fi
}
3
dialog --title "Date and Time" --msgbox "\n$current_datetime\n"
10 50
}
case $choice in
1)
show_calendar
;;
2)
show_date_time
;;
3)
delete_file
;;
4)
break
;;
*)
;;
esac
done
}
4
# Call the main menu function to start the program
main_menu
5
df -h
} > "$temp_file"
# Display the information using dialog
dialog --title "Storage Information" --textbox "$temp_file" 30 100
# Remove the temporary file
rm -f "$temp_file"
}
6
# Remove the temporary file
rm -f "$temp_file"
}
# Exit program
exit_program() {
clear
exit 0
}
# Main menu
while true; do
choice=$(dialog --title "Main Menu" --menu "Choose an option" 15
60 9 \
1 "Operating System Information & Processes" \
2 "Computer CPU Information" \
3 "Memory Information" \
4 "Storage Information" \
5 "Mounted File-Systems Information" \
6 "Network Information" \
7 "Kernel Information" \
8 "Exit" 3>&1 1>&2 2>&3)
case $choice in
1) show_os_info_processes ;;
2) show_cpu_info ;;
7
3) show_memory_info ;;
4) show_storage_info ;;
5) show_mounted_info ;;
6) show_network_info ;;
7) show_kernel_info ;;
8) exit_program ;;
*)
dialog --title "Invalid Choice" --msgbox "Please try again" 10
60 ;;
esac
done
8
Outputs:
Main menu
9
System Info:
10