文档详情

linux操作系统实验报告_shell简单编程.doc

发布:2017-12-18约2.26千字共6页下载文档
文本预览下载声明
操作系统实验报告 院系:机电与信息工程学院 实验日期年 月 日 同组者(姓名、学号) 无 实验题目: 一、实验目的(包括:实验内容,实验原理,实验目标) 1)利用Shell编程,实现时间密码的验证 2)编写一个小程序,计算用户期望时间与系统时间的差值 3)编写一个Shell程序,使得程序在系统时间分钟值为5的倍数的时,自动备份此目录下的.png 文件到backup中(选做) 二、实验设计(包括:设计思路数据结构 使用linux虚拟机完成实验要求。 三、实验包括:1)利用Shell编程,实现时间密码的验证 附:源代码如下 #!/bin/bash #Program: User can test the timepassword.用户可以验证时间密码 #History:2012/11/03 First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH Date=`date +%Y%m%d%H%M` read -p Please input the password : password while [ $password != $Date ] do read -p You have the wrong password , please input the right one : password done if [ $password == $Date ]; then echo Congratulations ! You have won the this test ! exit 0 fi 2)编写一个小程序,计算用户期望时间与系统时间的差值 附:源代码 #!/bin/bash #Program: User can get the days to his expected date. #得到距离用户期望日期的天数或者已过天数。 #History:2012/11/04 First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH Time=`date +%Y%m%d` echo Now is the time $Time read -p Enter the date: date1 date_test=echo $date1 | grep [0-9]\{8\} if [ $date_test == ];then echo Wrong form of date! Please try again:date1 exit 1 fi date_now=`date +%s` date_exp=`date --date=$date1 +%s` date_dif_s=$(($date_exp-$date_now)) date_dif=$(($date_dif_s/60/60/24)) if [ $date_dif -gt 0 ];then echo $(($date_dif+1)) day(s) later to your expected date. elif [ $date_dif -lt 0 ];then echo Your days is $((-1*$date_dif)) days before. else echo Your expected day is today. fi 3)编写一个Shell程序,使得程序在系统时间分钟值为5的倍数的时,自动备份此目录下的.png 文件到backup中(选做) 源代码: #!/bin/bash #Program: User can backup the png files every 5 minutes. #History:2012/11/04 First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH echo This program helps you to backup the png files every 5 minutes. backdir=./backup minute=`date +%M` next=$(($minute%5)) if [ $n
显示全部
相似文档