then echo"your operate is cancel echo "your input is bad 脚本执行的情况,如下。 zhaodongfeng a Teach Server /shells bash usermanage sh Please input your username zhaodongfeng your username is zhaodongfeng, are you sure?y or n):y zhaodongfeng is create success Please change password for zhaodongfeng Enter new UNIX password Retype new UNIX password passwd: password updated successfull 四、She1l编程案例二:备份 MySQL数据库 目的 通过Shel1脚本实现 My SQL数据的自动备份 案例: My SQL数据库备份 #!/bin/bash userpassword="zdf123456 foldername="/var/www/databasebackup BKdatabasefilename="SBKdatabase-date'+%y%m%d%H%M".sql d sBKfoldername mysqldump-uSusername-pSuserpassword SBKdatabase>SBKdatabasefilename echo"MysQL database $BKdatabase Backup success 13《LInux操作系统》讲稿/河南中医学院/阮晓龙/rl@hactcm.edu.cn13 《Linux 操作系统》讲稿 / 河南中医学院 / 阮晓龙 / rxl@hactcm.edu.cn then echo "your operate is cancel." break else echo "your input is bad." break fi #end 脚本执行的情况,如下。 zhaodongfeng@TeachServer:~/shell$ bash usermanage.sh Please input your username:zhaodongfeng your username is zhaodongfeng,are you sure?(y or n):y zhaodongfeng is create success. Please change password for zhaodongfeng. Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully 四、Shell 编程案例二:备份 MySQL 数据库 目的: 通过 Shell 脚本实现 MySQL 数据的自动备份。 案例:MySQL 数据库备份 #!/bin/bash username="zhaodongfeng" userpassword="zdf123456" BKdatabase="student" BKfoldername="/var/www/databasebackup/" BKdatabasefilename="$BKdatabase-`date '+%y%m%d%H%M'`.sql" cd $BKfoldername mysqldump -u$username -p$userpassword $BKdatabase>$BKdatabasefilename cd ~ echo "MySQL database $BKdatabase Backup success!