+-
首页 专栏 linux 文章详情
crab 发布于 5 月 14 日
关注作者
关注作者
0
OS大作业一:shell编程
readInfo.sh
#!/bin/bash read -t 30 -n 1 -p "Press 'w' to write in, Press 's' to search, Press 'r' to remove :" ch echo -e "\n" if [ $ch == "w" ] then if [ ! -d /tmp/info ] then mkdir /tmp/info echo -e "User\tPlatform\tID\tPassword\n" > /tmp/info/passwd.txt fi read -t 30 -p "User:" user read -t 30 -p "Platform:" plat read -t 30 -p "ID:" id read -t 30 -s -p "Password:" key echo -e "\n" echo -e "$user\t$plat\t$id\t$key\n" >> /tmp/info/passwd.txt elif [ $ch == "s" ] then read -t 30 -p "Please input the Platform for searhing:" splt read -t 30 -p "Please input ID for searching:" sid grep "$splt.$sid" /tmp/info/passwd.txt | awk '{printf "The password is :"$4"\n"}' elif [ $ch == "r" ] then read -t 30 -p "Please input the Platform for removing:" rplt read -t 30 -p "Please input the ID for removing:" rid sed -i '/'"$rplt.$rid"'/d' /tmp/info/passwd.txt &>/dev/null else echo -e "Wrong instruction!\n" fi echo -e "\n"
Backup.sh
#!/bin/bash ntpdate asia.pool.ntp.org &>/dev/null date=$(date +%y%m%d) size=$(du -sh /etc) if [ -d /tmp/dbback ] then echo "Date is :$date" > /tmp/dbback/db.txt echo "Size is :$size" >> /tmp/dbback/db.txt cd /tmp/dbback tar -zcf etc_$date.tar.gz /etc db.txt &>/dev/null rm -rf /tmp/dbback/db.txt else mkdir /tmp/dbback echo "Date is :$date" > /tmp/dbback/db.txt echo "Size is :$size" >> /tmp/dbback/db.txt cd /tmp/dbback tar -zcf etc_$date.tar.gz /etc db.txt &>/dev/null rm -rf /tmp/dbback/db.txt fi
linux
阅读 33 更新于 5 月 14 日
赞
收藏
分享
本作品系原创, 采用《署名-非商业性使用-禁止演绎 4.0 国际》许可协议
crab
1 声望
0 粉丝
0 条评论
得票数 最新
提交评论
你知道吗?
注册登录
crab
1 声望
0 粉丝
宣传栏
目录
▲
readInfo.sh
#!/bin/bash read -t 30 -n 1 -p "Press 'w' to write in, Press 's' to search, Press 'r' to remove :" ch echo -e "\n" if [ $ch == "w" ] then if [ ! -d /tmp/info ] then mkdir /tmp/info echo -e "User\tPlatform\tID\tPassword\n" > /tmp/info/passwd.txt fi read -t 30 -p "User:" user read -t 30 -p "Platform:" plat read -t 30 -p "ID:" id read -t 30 -s -p "Password:" key echo -e "\n" echo -e "$user\t$plat\t$id\t$key\n" >> /tmp/info/passwd.txt elif [ $ch == "s" ] then read -t 30 -p "Please input the Platform for searhing:" splt read -t 30 -p "Please input ID for searching:" sid grep "$splt.$sid" /tmp/info/passwd.txt | awk '{printf "The password is :"$4"\n"}' elif [ $ch == "r" ] then read -t 30 -p "Please input the Platform for removing:" rplt read -t 30 -p "Please input the ID for removing:" rid sed -i '/'"$rplt.$rid"'/d' /tmp/info/passwd.txt &>/dev/null else echo -e "Wrong instruction!\n" fi echo -e "\n"
Backup.sh
#!/bin/bash ntpdate asia.pool.ntp.org &>/dev/null date=$(date +%y%m%d) size=$(du -sh /etc) if [ -d /tmp/dbback ] then echo "Date is :$date" > /tmp/dbback/db.txt echo "Size is :$size" >> /tmp/dbback/db.txt cd /tmp/dbback tar -zcf etc_$date.tar.gz /etc db.txt &>/dev/null rm -rf /tmp/dbback/db.txt else mkdir /tmp/dbback echo "Date is :$date" > /tmp/dbback/db.txt echo "Size is :$size" >> /tmp/dbback/db.txt cd /tmp/dbback tar -zcf etc_$date.tar.gz /etc db.txt &>/dev/null rm -rf /tmp/dbback/db.txt fi