Welcome to the Linux Foundation Forum!

Urgent Linux scripting help

i wrote a script in Linux Kate

this script is to show all system information avalible on the computer in a menu form but when pressed option 1 to show jus the hard drive information it shows all of the information avalible

and i got a backup code which is not paste in the below script which does not work any1 know a easy backup script jus for system files

any1 could help

#!/bin/bash

while :

do

echo "1.Output System specifications"

echo "2.Display Virtual memory statistics"

echo "3.Display memory usage"

echo "4.Estimate file space usage"

echo "5.Display free disk space"

echo "6.Backup files"

echo "7.EXIT"

echo -n "Enter a number between 1 and 7 and press [ENTER];"

read opt

case $opt in

1) uname ;;

2) vmstat ;;

3) free ;;

4) du ;;

5) df ;;

#6)

7) echo "Bye $USER";

exit 1;;

esac

sleep 2

clear

# harddisk information

if [ -d /proc/ide/hda ]

then

echo -e "Hard disk information:"

echo -e "--------------------------------------------------------------------"

echo -e "Model: `cat /proc/ide/hda/model` "

echo -e "Driver: `cat /proc/ide/hda/driver` "

echo -e "Cache size: `cat /proc/ide/hda/cache` "

fi

echo -e "--------------------------------------------------------------------"

echo -e "Computer CPU Information:"

echo -e "--------------------------------------------------------------------"

cat /proc/cpuinfo

echo -e "--------------------------------------------------------------------"

echo -e "Computer Memory Information:"

echo -e "--------------------------------------------------------------------"

cat /proc/meminfo

echo -e "--------------------------------------------------------------------"

echo -e "File System (Mount):"

echo -e "--------------------------------------------------------------------"

cat /proc/mounts

done

Comments

  • Posts: 2,177
    I got creative, here you go all you need to do it call the functions for the additional operations.
    1. #!/bin/bash
    2.  
    3. function SystemSpecs {
    4. uname -a
    5. }
    6.  
    7. function VmStats {
    8. vmstat
    9. }
    10.  
    11. function MemStats {
    12. free
    13. }
    14.  
    15. function FileSpace {
    16. du
    17. }
    18.  
    19. function FreeSpace {
    20. df
    21. }
    22.  
    23. function BackupSystem {
    24. echo Backup Started `date` >> ~/backuplog
    25. mkdir /mnt/usbdrive/backups/`date +%Y%m%d`
    26. tar -czf /mnt/usbdrive/backups/`date +%Y%m%d`/data.tar.gz /data
    27. echo Backup Completed `date` >> ~/backuplog
    28. }
    29.  
    30. function ExitMessage {
    31. echo "Bye $USER"
    32. }
    33.  
    34. function HdInfo {
    35. if [ -d /proc/ide/hda ]
    36. then
    37. echo -e "Hard disk information:"
    38. echo -e "--------------------------------------------------------------------"
    39. echo -e "Model: `cat /proc/ide/hda/model` "
    40. echo -e "Driver: `cat /proc/ide/hda/driver` "
    41. echo -e "Cache size: `cat /proc/ide/hda/cache` "
    42. fi
    43. }
    44.  
    45. function CpuInfo {
    46. echo -e "--------------------------------------------------------------------"
    47. echo -e "Computer CPU Information:"
    48. echo -e "--------------------------------------------------------------------"
    49. cat /proc/cpuinfo
    50. }
    51.  
    52. function CMemInfo {
    53. echo -e "--------------------------------------------------------------------"
    54. echo -e "Computer Memory Information:"
    55. echo -e "--------------------------------------------------------------------"
    56. cat /proc/meminfo
    57. }
    58.  
    59. function FsInfo {
    60. echo -e "--------------------------------------------------------------------"
    61. echo -e "File System (Mount):"
    62. echo -e "--------------------------------------------------------------------"
    63. cat /proc/mounts
    64. }
    65.  
    66. while :
    67. do
    68.  
    69. clear
    70. printf "|-------------------------------------------------------------|\n"
    71. printf "| Choose which system information you need |\n"
    72. printf "|-------------------------------------------------------------|\n"
    73. printf "\n"
    74. printf "1. Output System specifications\n"
    75. printf "2. Display Virtual memory statistics\n"
    76. printf "3. Display memory usage\n"
    77. printf "4. Estimate file space usage\n"
    78. printf "5. Display free disk space\n"
    79. printf "6. Backup files\n"
    80. printf "7. EXIT\n"
    81. printf "\n"
    82. printf "Enter a number between 1 and 7 and press [ENTER]: "
    83. read opt
    84. printf "\n"
    85.  
    86.  
    87. case "$opt" in
    88. 1)
    89. SystemSpecs
    90. ;;
    91. 2)
    92. VmStats
    93. ;;
    94. 3)
    95. MemStats
    96. ;;
    97. 4)
    98. FileSpace
    99. ;;
    100. 5)
    101. FreeSpace
    102. ;;
    103. 6)
    104. BackupSystem
    105. ;;
    106. 7)
    107. ExitMessage
    108. exit 1
    109. ;;
    110. else)
    111. sleep 2
    112. clear
    113. ;;
    114. esac
    115.  
    116. clear
    117. done

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training