Linux Shell 脚本 - 备份/恢复

发布于 2024-12-17 12:40:02 字数 1366 浏览 0 评论 0原文

您好,Stackoverflow 社区,

我正在设计的 shell 脚本遇到了一个问题...

#!/bin/sh
while :
do
clear
echo "-----------------------------
-----------"
echo "***************Main Menu****************"
echo "----------------------------------------"
echo "1. Backup Word Document"
echo "2. Backup Spreadsheet"
echo "3. Backup Picture"
echo "4. Restore Word Documents"
echo "5. Restore Spreadsheet"
echo "6. Restore Picture"
echo "7. EXIT"

echo "----------------------------------------"
pause
echo -n "Enter your menu choice [1-7]:"
read yourch
case $yourch in
1) echo ; tar -cvf /Files/*.doc /WP/ ; read ;;

1) echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

2) echo ; tar -cvf /Files/*.xls /EXCEL/ ; read ;;

2) echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

3) echo ; tar -cvf /Files/*.jpg /PICS/ ; read ;;

3) echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

4) echo ; tar xvzf /WP/*.doc ; read ;;
5) echo ; tar xvzf /EXCEL/*.xls ; read ;;
6) echo ; tar xvzf /PICS/*.jpg ; read ;;
7) exit 0 ;;

*) echo "Please press a number between 1 to 7";

错误显示“cript: line 21:在意外标记附近出现语法错误” 'cript: line 21: 'case $yourch

有谁知道如何绕过这个错误?基本上我想做的是能够备份一组文件名为“.doc”的文件并将它们放在备份文件夹中。然后我可以将文件从该文件夹恢复到另一个文件夹。

亲切的问候,

Hi Community of Stackoverflow,

I am facing a problem here with my shell script that I am designing...

#!/bin/sh
while :
do
clear
echo "-----------------------------
-----------"
echo "***************Main Menu****************"
echo "----------------------------------------"
echo "1. Backup Word Document"
echo "2. Backup Spreadsheet"
echo "3. Backup Picture"
echo "4. Restore Word Documents"
echo "5. Restore Spreadsheet"
echo "6. Restore Picture"
echo "7. EXIT"

echo "----------------------------------------"
pause
echo -n "Enter your menu choice [1-7]:"
read yourch
case $yourch in
1) echo ; tar -cvf /Files/*.doc /WP/ ; read ;;

1) echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

2) echo ; tar -cvf /Files/*.xls /EXCEL/ ; read ;;

2) echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

3) echo ; tar -cvf /Files/*.jpg /PICS/ ; read ;;

3) echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

4) echo ; tar xvzf /WP/*.doc ; read ;;
5) echo ; tar xvzf /EXCEL/*.xls ; read ;;
6) echo ; tar xvzf /PICS/*.jpg ; read ;;
7) exit 0 ;;

*) echo "Please press a number between 1 to 7";

A error displays 'cript: line 21: syntax error near unexpected token 'in
'cript: line 21: 'case $yourch

Does anyone know how to by pass this error? Basically what im trying to do is be able to back up a set of files with the file name ".doc" and place them in a backup folder. I can then restore the files from this folder to another folder.

Kind Regards,

Ben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心 2024-12-24 12:40:02

我认为您缺少 esacdone 语句。

好的。使用这个:

#!/bin/sh
while :
do
  clear
  echo "-----------------------------
  -----------"
  echo "***************Main Menu****************"
  echo "----------------------------------------"
  echo "1. Backup Word Document"
  echo "2. Backup Spreadsheet"
  echo "3. Backup Picture"
  echo "4. Restore Word Documents"
  echo "5. Restore Spreadsheet"
  echo "6. Restore Picture"
  echo "7. EXIT"

  echo "----------------------------------------"

  echo -n "Enter your menu choice [1-7]:"
  read yourch
  case $yourch in
      1) echo ; 
     tar -cvf /Files/*.doc /WP/ ; read ;
     echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

      2)  echo ; tar -cvf /Files/*.xls /EXCEL/ ; read ;
      echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

      3) echo ; tar -cvf /Files/*.jpg /PICS/ ; read ;
     echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

      4) echo ; tar xvzf /WP/*.doc ; read ;;
      5) echo ; tar xvzf /EXCEL/*.xls ; read ;;
      6) echo ; tar xvzf /PICS/*.jpg ; read ;;
      7) exit 0 ;;

  *) echo "Please press a number between 1 to 7";;

  esac
done

I think you are missing esac and done statement.

Ok. Use this one :

#!/bin/sh
while :
do
  clear
  echo "-----------------------------
  -----------"
  echo "***************Main Menu****************"
  echo "----------------------------------------"
  echo "1. Backup Word Document"
  echo "2. Backup Spreadsheet"
  echo "3. Backup Picture"
  echo "4. Restore Word Documents"
  echo "5. Restore Spreadsheet"
  echo "6. Restore Picture"
  echo "7. EXIT"

  echo "----------------------------------------"

  echo -n "Enter your menu choice [1-7]:"
  read yourch
  case $yourch in
      1) echo ; 
     tar -cvf /Files/*.doc /WP/ ; read ;
     echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

      2)  echo ; tar -cvf /Files/*.xls /EXCEL/ ; read ;
      echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

      3) echo ; tar -cvf /Files/*.jpg /PICS/ ; read ;
     echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

      4) echo ; tar xvzf /WP/*.doc ; read ;;
      5) echo ; tar xvzf /EXCEL/*.xls ; read ;;
      6) echo ; tar xvzf /PICS/*.jpg ; read ;;
      7) exit 0 ;;

  *) echo "Please press a number between 1 to 7";;

  esac
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文