大学生linux大作业,关于linux: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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值