乐趣区

关于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
退出移动版